Showing posts with label sRGB2LAB. Show all posts
Showing posts with label sRGB2LAB. Show all posts

Saturday, July 26, 2014

Convert RGB to CIE LAB with explanation, MATLAB example


In this tutorial. I have explained what is RGB and CIE LAB color space. Then, I have shown an example in MATLAB where I converted an image from sRGB to LAB





Friday, June 29, 2012

Why choice of white point matters?

Imagine you have a sRGB image and you would like to convert it into lab color space.
So, how does it work ? It is calculated in two main steps
  1. sRGB to XYZ color space
  2. XYZ to Lab color space
During this color space conversion one of the major choice is the adapted white point. Let me show an example why adapted white matters! let us use the following image.
Fig 1: We will use this "peppers" image to show how choice of white point matters.
Please run the following code
I=imread('peppers.png');
figure, imshow(I);
srgb2lab_byA = makecform('srgb2lab', 'AdaptedWhitePoint',whitepoint('a'));
srgb2lab_byD50 = makecform('srgb2lab', 'AdaptedWhitePoint',whitepoint('d50'));
lab_A = applycform(I,srgb2lab_byA); 
lab_D50 = applycform(I,srgb2lab_byD50); 
figure;
subplot(1,2,1),imshow(lab_A(:,:,1)); title('sRGB to Lab by adapting to illuminant A');
subplot(1,2,2),imshow(lab_D50(:,:,1)); title('sRGB to Lab by adapting to illuminant D50');
luminance_diff=abs(lab_A(:,:,1)-lab_D50(:,:,1));
figure;% luminance difference is 40times enhanced for visualization
imshow(luminance_diff*40); title('luminance channel difference(40times enhanced for visualization) between A and D50');
Fig2 : sRGB2LAB conversion using illuminant A vs using illuminant D50


Since it is hard to see the difference from the above image, we can plot their difference




Fig3: Luminance difference while converting sRGB2lab using illuminant A vs illuminant D50; Original difference  is multiplied with 40 for visualization only