How to create an color sample from calculated LAB value?

From an created mask, I calculated the mean value of L, a and b channel. Now I would like to create an color sample (image) with this 'mean Lab value'.
This code does not work correct.
map = ones(60,60,3);
map = cast(map,'uint8');
map(:,:,1) = LMean*map(:,:,1);
map(:,:,2) = aMean*map(:,:,2);
map(:,:,3) = bMean*map(:,:,3);
figure('Name','Colour')
imshow(map);
Does anyone knows a solution?

 Accepted Answer

hi,
i think they answered your question, but just try this :
%i tried these values and the map is (cyan-like) Dark Blue
LMean=25.65;
aMean=35.69;
bMean=75.14;
map = ones(60,60,3);
map = cast(map,'uint8');
map(:,:,1) = LMean*map(:,:,1);
map(:,:,2) = aMean*map(:,:,2);
map(:,:,3) = bMean*map(:,:,3);
figure('Name','Colour')
imshow(map);

9 Comments

Looks like a dark blue to me, but that's in English. Type cyan into here: http://colorthesaurus.epfl.ch/ and see what different languages call it.
But anyway, you illustrated perfectly why what he's doing is deceptive. Yes, for LAB = (24,35,75) you get a dark blue or Cyan-like image in RGB. But we know from color theory that those LAB values are a dark, slightly orangish-yellow color, probably it's really a brown. See http://www.sightgrip.co.uk/bbstest.htm. So now you're representing a color that's brown by blue because you're doing something that does not make sense - that is mapping the L into red, the a into green, and the b into blue. So you get totally misleading gibberish, as expected, or at as I expected. I really don't think the original poster realizes this. A course in color science (like I taught this week to 30 scientists) would help. Admittedly, it can be confusing.
hi, yes its ~"Dark Blue" or "Dark Royal Blue" you are right, so you are teaching scientists ? great work, what category of scientists : Biologists? Engineers ?...
Most were chemists, but there were also statisticians and engineers there.
Yes, Image Analyst, I tested this code - it doesn't generate LAB color sample. But is it really possible to generate Lab color sample from measured value and represent it in consideration of Illum/Obs?
Not sure what code you tried, but take a look at the Computational Color Toolbox
Thank you once again. I rewrote the сode. It may be messy, but it works!
clear
load spectra.txt
% spectra represents a 1*31 matrix
spectra=spectra'
format shortG
% The second and third arguments relate to the % shortest and longest wavelengths available in the reflectance data.
% The fourth argument specifies the illuminant and observer combination to be used.
xyz=r2xyz(spectra,400,700,'d50_31')/100
lab=xyz2lab(xyz,'d50_31')
l=lab(:,1)
a=lab(:,2)
b=lab(:,3)
LAB = cat(3,l,a,b);
lab_uint16=lab2uint16(LAB)
imwrite(lab_uint16,'grun.tiff','tif','ColorSpace','CIELab')
This doesn't look like Youssef's code. What did you base this off of? Was this from Professor Westland's Computation Colour Toolbox like I referred you to?
I took this from Computation Colour Toolbox
xyz=r2xyz(spectra,400,700,'d50_31')/100
lab=xyz2lab(xyz,'d50_31')
Everything else - just converting.

Sign in to comment.

More Answers (1)

You need to use imshow(map, []). The [] is important if you have floating point values outside the range of 0-1. But I have to tell you that viewing an LAB image as an RGB image makes little sense. The color you see will be renedered in RGB, with R being the lightness, green being the redness to greenness axis, and blue being the yellowness to blueness axis. The image will likely look like it's made of random colors.
You might want to use makecform('lab2srgb'.....) to create a "valid" (meaning it uses the "book formula" and is not colorimetrically accurate) RGB image.

4 Comments

If the values of LMean etc are in the 0 to 1 range then because map() is initialized to uint8 one's, the result would be to round() the values to 0 or 1 exactly. The values would have to be in 0-11 or 0-127 or 0-240 or 0-255 to get something reasonable.
Thanks Image Analyst,
Would using the 'book formula' result in the same color that I would get using 'Photoshop', to generate the color?
So, Martijn, are we done here, or not? If so, please officially "Accept" the answer. Thanks.

Sign in to comment.

Tags

Asked:

on 28 Feb 2013

Commented:

on 3 Nov 2013

Community Treasure Hunt

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

Start Hunting!