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?

1 件のコメント

Walter Roberson
Walter Roberson 2013 年 2 月 28 日
What range of values are LMean, aMean, bMean ?

サインインしてコメントする。

 採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 3 月 1 日
編集済み: Youssef Khmou 2013 年 3 月 1 日

0 投票

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 件のコメント

Image Analyst
Image Analyst 2013 年 3 月 1 日
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.
Youssef  Khmou
Youssef Khmou 2013 年 3 月 1 日
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 ?...
Image Analyst
Image Analyst 2013 年 3 月 1 日
Most were chemists, but there were also statisticians and engineers there.
Oleg
Oleg 2013 年 11 月 1 日
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?
Image Analyst
Image Analyst 2013 年 11 月 1 日
Not sure what code you tried, but take a look at the Computational Color Toolbox
Oleg
Oleg 2013 年 11 月 2 日
Thanks!
Oleg
Oleg 2013 年 11 月 2 日
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')
Image Analyst
Image Analyst 2013 年 11 月 2 日
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?
Oleg
Oleg 2013 年 11 月 3 日
I took this from Computation Colour Toolbox
xyz=r2xyz(spectra,400,700,'d50_31')/100
lab=xyz2lab(xyz,'d50_31')
Everything else - just converting.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 2 月 28 日

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 件のコメント

Walter Roberson
Walter Roberson 2013 年 3 月 1 日
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.
Martijn
Martijn 2013 年 3 月 1 日
Thanks Image Analyst,
Would using the 'book formula' result in the same color that I would get using 'Photoshop', to generate the color?
Image Analyst
Image Analyst 2013 年 3 月 1 日
Probably.
Image Analyst
Image Analyst 2013 年 11 月 1 日
So, Martijn, are we done here, or not? If so, please officially "Accept" the answer. Thanks.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

タグ

質問済み:

2013 年 2 月 28 日

コメント済み:

2013 年 11 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by