MATLAB: Color transform to lab then to rgb

colorImage Processing Toolboxtransfer function

Hi i have a doubt, I am working of color transformation and trying to find a better color space for my work. I wrote the code using matlab help but all i can see is a error, i amnot sure how to modify my code. My input image is a facce of a person in white background. could you help in correcting my code. And also I have one more question, what is the difference between lab2srgb or srgbt2lab inbuilt code in matlab from using applycform?
my code
%%convert to different color spaces:
%lab color space
I = imread('facergbimg.jpg');
rgb = reshape(im2double(I)/255,[],3);
cform = makecform('srgb2lab', 'AdaptedWhitePoint', whitepoint('D65'));
lab = applycform(rgb,cform);
transform = makecform('lab2srgb','AdaptedWhitePoint', whitepoint('D65'));
srgb = applycform(lab,tranform);
% labresh = reshape(rgb.*lab, size(I));
% bckrgb = reshape(reshape(labresh,[],3)*inv(lab),[],size(labresh)); (here i thought of using inverse & reshape function to get back to rgb, but didnot work)
subplot(1,2,1),imshow(lab);
subplot(1,2,2),imshow(srgb);
% %

Best Answer

Try this:
rgbImage = imread('peppers.png');
labImage = rgb2lab(rgbImage);
lImage = labImage(:, :, 1);
aImage = labImage(:, :, 2);
bImage = labImage(:, :, 3);
% Display everything


subplot(2, 2, 1);
imshow(rgbImage);
fontSize = 20;
title('RGB Image', 'FontSize', fontSize);
subplot(2, 2, 2);
imshow(lImage, []);
title('L Image', 'FontSize', fontSize);
% Display everything
subplot(2, 2, 3);
imshow(aImage, []);
title('A Image', 'FontSize', fontSize);
% Display everything
subplot(2, 2, 4);
imshow(bImage, []);
title('B Image', 'FontSize', fontSize);