Mean of CIE L*a*b values in a masked image
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Felipe
am 24 Mai 2023
Kommentiert: Image Analyst
am 25 Mai 2023
Hello,
I am trying to get the mean of LAB values on a masked image, but i suspect that my code is computing the black and not only the colors masked. I'm a new matlab user and I apologize if my code is a mess.
Thank you very much for your attention.
Felipe Castro
% CIE L*a*b transformation
I = rgb2lab(Image);
% L max and min for the segmantation
LMin = 0.0;
LMax = 30.0;
sliderBW = (I(:,:,1) >= LMin) & (I(:,:,1) <= LMax);
BW = sliderBW;
maskedRGBImage = Icropped;
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
maskedLAB = rgb2lab(maskedRGBImage);
% mean per pixel
mean_Lab = mean(maskedLAB, 4);
% mean overall
mean_L = mean2(mean_Lab(:,:,1));
mean_a = mean2(mean_Lab(:,:,2));
mean_b = mean2(mean_Lab(:,:,3));
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 24 Mai 2023
Yes, it was a mess but that's OK, I fixed it:
% Read in demo image.
rgbImage = imread('peppers.png');
subplot(1, 2, 1);
imshow(rgbImage);
title('Original RGB Image')
% CIE L*a*b transformation
labImage = rgb2lab(rgbImage);
% L max and min for the segmantation
LMin = 0.0;
LMax = 30.0;
mask = (labImage(:,:,1) >= LMin) & (labImage(:,:,1) <= LMax);
subplot(1, 2, 2);
imshow(mask);
title('Mask Image')
% Get individual LAB images
[lImage, aImage, bImage] = imsplit(labImage);
% Get the mean ONLY within the mask region.
mean_L = mean(lImage(mask))
mean_a = mean(aImage(mask))
mean_b = mean(bImage(mask))
2 Kommentare
Image Analyst
am 25 Mai 2023
You're welcome. Just be aware that those LAB are just arbitrary values gotten from book formulas. They are not the real LAB values you'd get from the objects in your scene if you had used a colorimeter or spectrophotometer on them. For example if you cut the exposure by half the L value would be about half even though the object in your scene didn't change its intrinsic color at all. The "true" LAB values of the object are intrinsic to the object and illuminant, though you can get almost whatever LAB you want just by changing the lighting and exposure on your scene.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!