123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /**
- * @file ColorSpace.cpp
- * @brief __DESC__
- * @author Michael Koch
- * @date 07/28/2008
- */
- #include <vislearning/nice.h>
- #include <iostream>
- #include "ColorSpace.h"
- #include <math.h>
- #include "vislearning/baselib/cc.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- //bad position for this function
- void ColorSpace::ColorImagetoMultiChannelImage(const NICE::ColorImage &imgrgb,NICE::MultiChannelImageT<double> &genimg)
- {
- genimg.reInit(imgrgb.width(),imgrgb.height(),3,true);
- for(int y=0;y<imgrgb.height();y++)
- {
- for(int x=0;x<imgrgb.width();x++)
- {
- double r,g,b;
- r=imgrgb.getPixelQuick(x,y,0);
- g=imgrgb.getPixelQuick(x,y,1);
- b=imgrgb.getPixelQuick(x,y,2);
- genimg.set(x,y,r,0);
- genimg.set(x,y,g,1);
- genimg.set(x,y,b,2);
- }
- }
- }
- /*
- //TODO test it
- int checkRange(int in,int min=0,int max=255)
- {
- int out=in;
-
- if(in<min)
- {
- out=min;
- }
- if(in>max)
- {
- out=max;
- }
- return out;
- }
- NICE::ColorImage ColorSpace::rgbtohsl(const NICE::ColorImage &imgrgb)
- {
- NICE::ColorImage imghsl (imgrgb.width(), imgrgb.height());
- for(int x=0;x<imgrgb.width();x++)
- {
- for(int y=0;y<imgrgb.height();y++)
- {
- double R,G,B,H,S,L;
- R=(double)imgrgb.getPixel(x,y,0)/255.0;
- G=(double)imgrgb.getPixel(x,y,1)/255.0;
- B=(double)imgrgb.getPixel(x,y,2)/255.0;
- ColorConversion::ccRGBtoHSL(R,G,B,&H,&S,&L);
- imghsl.setPixel(x,y,0,(int)round(H*255.0));
- imghsl.setPixel(x,y,1,(int)round(S*255.0));
- imghsl.setPixel(x,y,2,(int)round(L*255.0));
- }
- }
- return imghsl;
- }
- NICE::ColorImage ColorSpace::hsltorgb(const NICE::ColorImage &imghsl)
- {
- NICE::ColorImage imgrgb (imghsl.width(), imghsl.height());
- for(int x=0;x<imghsl.width();x++)
- {
- for(int y=0;y<imghsl.height();y++)
- {
- double R,G,B,H,S,L;
- H=(double)imghsl.getPixel(x,y,0)/255.0;
- S=(double)imghsl.getPixel(x,y,1)/255.0;
- L=(double)imghsl.getPixel(x,y,2)/255.0;
-
- ColorConversion::ccHSLtoRGB(H,S,L,&R,&G,&B);
- imgrgb.setPixel(x,y,0,(int)round(R*255.0));
- imgrgb.setPixel(x,y,1,(int)round(G*255.0));
- imgrgb.setPixel(x,y,2,(int)round(B*255.0));
- }
- }
- return imgrgb;
- }
-
- NICE::ColorImage ColorSpace::rgbtolab(const NICE::ColorImage &imgrgb)
- {
- NICE::ColorImage imglab (imgrgb.width(), imgrgb.height());
- //preprocessing RGB to XYZ
- for(int x=0;x<imgrgb.width();x++)
- {
- for(int y=0;y<imgrgb.height();y++)
- {
- double R,G,B,X,Y,Z,L,a,b;
- R=(double)imgrgb.getPixel(x,y,0)/255.0;
- G=(double)imgrgb.getPixel(x,y,1)/255.0;
- B=(double)imgrgb.getPixel(x,y,2)/255.0;
- ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
- ColorConversion::ccXYZtoCIE_Lab(X,Y,Z,&L,&a,&b,0);
- imglab.setPixel(x,y,0,(int)round(L*255.0));
- imglab.setPixel(x,y,1,(int)round(a*255.0));
- imglab.setPixel(x,y,2,(int)round(b*255.0));
- }
- }
- showImage ( *imglab.getChannel(0), "L" );
- return imglab;
- }
- NICE::ColorImage ColorSpace::labtorgb(const NICE::ColorImage &imglab)
- {
- NICE::ColorImage imgrgb (imglab.width(), imglab.height());
- //preprocessing RGB to XYZ
- for(int x=0;x<imglab.width();x++)
- {
- for(int y=0;y<imglab.height();y++)
- {
- double R,G,B,X,Y,Z,L,a,b;
- L=(double)imglab.getPixel(x,y,0)/255.0;
- a=(double)imglab.getPixel(x,y,1)/255.0;
- b=(double)imglab.getPixel(x,y,2)/255.0;
-
- ColorConversion::ccCIE_LabtoXYZ(L,a,b,&X,&Y,&Z,0);
- ColorConversion::ccXYZtoRGB(X,Y,Z,&R,&G,&B,0);
- imgrgb.setPixel(x,y,0,(int)round(R*255.0));
- imgrgb.setPixel(x,y,1,(int)round(G*255.0));
- imgrgb.setPixel(x,y,2,(int)round(B*255.0));
- }
- }
- return imgrgb;
- }
- NICE::ColorImage ColorSpace::rgbtolms(const NICE::ColorImage &imgrgb)
- {
- NICE::ColorImage imglms=NICE::ColorImage(imgrgb.width(),imgrgb.height());
- //preprocessing RGB to XYZ
- for(int x=0;x<imgrgb.width();x++)
- {
- for(int y=0;y<imgrgb.height();y++)
- {
- double R,G,B,X,Y,Z,L,M,S;
- R=(double)imgrgb.getPixelQuick(x,y,0)/255.0;
- G=(double)imgrgb.getPixelQuick(x,y,1)/255.0;
- B=(double)imgrgb.getPixelQuick(x,y,2)/255.0;
-
- ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
- ColorConversion::ccXYZtoLMS(X,Y,Z,&L,&M,&S);
- imglms.setPixelQuick(x,y,0,checkRange((int)round(L*255.0)));
- imglms.setPixelQuick(x,y,1,checkRange((int)round(M*255.0)));
- imglms.setPixelQuick(x,y,2,checkRange((int)round(S*255.0)));
- }
- }
- return imglms;
- }*/
|