Tuesday, March 12, 2013

watch out while using sRGB2lab

Imagine you have a 8 bit/color channel (24bit image) and you want to convert RGB values (assuming in sRGB color space) into LAB color space. SO you do the following


rgb=imread('peppers.png');
lab = applycform(rgb,makecform('srgb2lab'));

Where rgb is a NxMx3 matrix of unint8 type and so does the lab. Everything seems fine! But try the following: 

Lmax= max(max(lab(:,:,1))) % maximum L of LAB should be within 100 

but is it the case? NO? 
You will notice that Lmax is beyond 100 and the reason is lab is in uint8 type

Therefore, if you want a normalized L value from LAB do the following

lab_d=lab2double(lab); % normalization !!!

Now try 
max(max(lab_d(:,:,1)))  % L should be  <=100

Therefore, watch out! But, color your life! :)

No comments:

Post a Comment

Please ask if anything is not clear enough..........