How to convert Lab to RGB image and its matlab code?

In my program,first converted rgb image to lab but after processing the image , i want convert Lab to rgb image. so i request you, pls provide matlab code for converting lab to rgb image?

 Accepted Answer

help cform tells you
rgb = imread('peppers.png');
cform = makecform('srgb2lab');
lab = applycform(rgb, cform);

7 Comments

the above matlab code is for rgb to lab but not converse. thanks.
That's just another cform:
cform_lab2srgb = makecform('lab2srgb');
rgb = applycform(lab, cform_lab2srgb);
thank you.its working well. i need mathematical equations for documentation purpose to convert CIELab to rgb image. is there link pls?
thanks in advance.
For standard "book formulas" you can go to http://www.easyrgb.com/index.php?X=MATH. I rarely use book formulas if you need actual LAB values like you'd get from a spectrophotometer or chromameter. Why? Well, an object has an intrinsic LAB color but if you snap images with a camera, you can get virtually whatever RGB values you want out of it by adjusting exposure or other camera parameters. Of course all those different RGB values will give different LAB values if you just use the book formula, NOT the true intrinsic LAB values. In what I do, I need accurate LAB values, not arbitrary ones.
I want to convert rgb images to lab. But above code is not working.It not shows any output after the conversion.Help me out
@zee falcon: what output do you expect? How are you checking it?
zee, you can also use rgb2lab(). But like Steven asked, what output are you expecting? You get an image. And do see that image you can use imshow(), or you can just look at it's values in the variable editor in the workspace. But no output will get "shown" unless you do one of those two things. Otherwise all you get is a new variable.

Sign in to comment.

More Answers (2)

Try this
labImage = rgb2lab(rgbImage);

3 Comments

For the reverse direction, it's
rgbImage = lab2rgb(labImage);
There are also options that you can specify -- see the help.
I want to convert rgb images to lab. But above code is not working.It not shows any output after the conversion.Help me out

Sign in to comment.

2 Comments

i am getting error after compile the above matalb code: ??? Error using ==> times Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> Lab2RGB at 34 fY = (~YT) .* (L / 903.3) + YT .* fY;

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!