I am using OpenCV for some of my image processing related codes. I am stuck at a particular point.
In a particular code, I need to compare the pixel values of an image based on it`s CIE L*a*b* values. I know for BGR we can do something like this :
// img is the image, suppose
uchar *data = ( uchar* )img->imageData;
for(i=0; i< img->height; i++)
for(j=0; j<img->width; j++)
{
b = data[i*img->widthStep + j*img->nChannels + 0];
g = data[i*img->widthStep + j*img->nChannels + 1];
r = data[i*img->widthStep + j*img->nChannels + 2];
}
My question is, can we do something similar for l*a*b* color model also ? I mean at first I convert the image by
cvCvtColor(img, lab, CV_BGR2Lab);
then accessing the individual channel info like in the above case (since L*a*b* is also made up of 3 channels, if am not wrong), can we get the pixel values ??
The reason I am asking this is I tried to implement it, but I`m getting some real weird values like very high negative numbers ( I used int datatype instead of uchar since I was unsure about the range ‘a’ and ‘b’ can have ) whereas in Wikipedia I saw that ‘L’ can have values only in the range of 0 to 100. So how exactly can I get those pixel values ??
Thanks in advance !!
Surely, you can do that, why not? Be aware however, that output is somewhat specific (since
aandbcan be negative):note that
Lis also scaled to 0-255 range (instead of 0-100). See more here.BTW how can you get negative numbers if your data type is unsigned char?