How to extract L,a and b from a cell

I have 6 images and store it in a cell. I then convert it to LAB space. But how do I get the L, a and b channel from the cell? Here's my code:
clear
imgformat = 'LCC%d.jpg';
for k = 1:6
LCC{k} = imread(sprintf(imgformat, k));
cform = makecform('srgb2lab');
lab_Image{k} = applycform(LCC{k},cform);
end
How am I going to get all the L, a and b channel of those 6 images? How should I use the LChannel = lab_Image(:, :, 1); code when working with cell?
Thanks

 Réponse acceptée

Image Analyst
Image Analyst le 14 Déc 2013
No, you made lab_Image a cell , not a regular 3D array . The 3D array is actually INSIDE the cell so you need to pull it out first - at least that is the least confusing and most intuitive way to do it.
theImage = lab_Image{theIndex}; % theIndex can be from 1 to 6
LChannel = theImage(:,:,1);
AChannel = theImage(:,:,2);
BChannel = theImage(:,:,3);

15 commentaires

Image Analyst
Image Analyst le 14 Déc 2013
Modifié(e) : Image Analyst le 14 Déc 2013
IMPORTANT NOTE: Note that lab_Image{theIndex}; uses braces not parentheses , but theImage(:,:,1); uses parentheses not braces. The FAQ will explain why.
Elvin
Elvin le 14 Déc 2013
I know that the 3D array is inside the cell. But how will I use the for loop to get all the LAB channel of all those 6 images? I'm still confused :(
Elvin
Elvin le 14 Déc 2013
Modifié(e) : Elvin le 14 Déc 2013
How will I use this code to extract LAB of all the 6 matrix in the lab_Image cell?
LChannel = lab_Image(:, :, 1);
AChannel = lab_Image(:, :, 2);
BChannel = lab_Image(:, :, 3);
I did this but I'm not sure if I'm doing the right thing:
clear
imgformat = 'LCC%d.jpg';
for k = 1:6
LCC{k} = imread(sprintf(imgformat, k));
cform = makecform('srgb2lab');
lab_Image{k} = applycform(LCC{k},cform);
LChannel{k} = lab_Image{k}(:, :, 1);
AChannel{k} = lab_Image{k}(:, :, 2);
BChannel{k} = lab_Image{k}(:, :, 3);
end
Image Analyst
Image Analyst le 14 Déc 2013
I showed you how to get the lab images. If you want to store them all in a cell array for use later, like you did, you can do that. Or else just use them somehow inside the loop and discard them/overwrite them when the next loop iteration begins, which is what I did. If you don't need them after the loop, then don't store them in a cell array - there's no need to.
Elvin
Elvin le 14 Déc 2013
I see. Thanks for that. I think I'll just use the LChannel{k} = lab_Image{k}(:, :, 1); since I'll be using them later when solving for the deltaE.
Thank you very much :)
It's simpler to do
lab_Image = applycform(LCC{k},cform);
LChannel{k} = lab_Image(:, :, 1);
AChannel{k} = lab_Image(:, :, 2);
BChannel{k} = lab_Image(:, :, 3);
unless you think you'll need the full 3D image later for some reason. Otherwise there's no reason to store lab_Image as a cell for every single image.
Elvin
Elvin le 15 Déc 2013
I think I still need to store lab_Image as a cell since this 6 images will serve as my standard/reference. I will use 10 test images. I will compute the deltaE of each test images with the 6 standard images. Example, for 1 test image, it will be used to compute the 6 deltaE of those. And I will find the lowest value of the deltaE and then the lowest value will serve as the one closest to the standard.
Image Analyst
Image Analyst le 15 Déc 2013
That's fine but you can do all that with only LChannel, AChannel, and BChannel - you don't need lab_image anymore. You have 6 cells for each LChannel, AChannel, and BChannel - every image has a set. Why do you think you need lab_image anymore? You don't. There is nothing that you would do with lab_image that can't be done easier with LChannel, AChannel, and BChannel. Please think about it.
Elvin
Elvin le 16 Déc 2013
I used the lab_Image to store the data after the srgd2lab conversion.
Elvin
Elvin le 16 Déc 2013
Can you review my code so far? Here it is. I just need some comments/recommendations. By the way, I used the Delta E CIE 1994. Here's the link to my program: https://www.dropbox.com/s/u8rculvextza0aa/LCC.m
Elvin
Elvin le 16 Déc 2013
By the way, did you received my email before?
Image Analyst
Image Analyst le 16 Déc 2013
I know you used lab_Image to get the data in the new color space. I hope you realize now that after you've used it to pull out the individual L, A, and B channels, that you don't need it anymore.
I don't take email at this account, so no, I didn't see any email.
Elvin
Elvin le 16 Déc 2013
Have you seen my code? Can you help me with? I'm really confused with what I'm doing. Sorry for that, I'm just new to MATLAB, especially to image processing. It's my first time studying this. And I was forced to study this because of our project.
My question is, are my codes on the right track?
By the way, I'll make clear of our project. In our project, we are going to test the nitrogen deficiency of rice plants based on their leaf color. So here's our setup:
1. We have 6 shades of green that will be used as reference.
2. We will get the LAB channels of all those 6 images and store it.
3. We will then take a picture of a rice leaf (with a black background) and this picture will be used as the test image.
4. We will get the LAB channel of the test image.
5. We will solve 6 DeltaE (1 test image to 6 reference images) and see which one will have the lowest value. The result is that, the lowest value of DeltaE means that the color of the leaf is closer to one of the 6 reference images.
I hope you understand our project. Also, can you show me an easy way how to do it? I've been doing this for 3 days and I think it's still wrong. :(
Thank you very much for the help and God bless.
Elvin
Elvin le 18 Déc 2013
Any update with this sir?

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 14 Déc 2013
Modifié(e) : Matt J le 14 Déc 2013
Assuming all 6 images are the same size, you can concatenate
LabData=cat(4,lab_Image{:});
and then just index
LChannel=LabData(:,:,1,:);

3 commentaires

Elvin
Elvin le 14 Déc 2013
I've tested it and see the data in the workspace but I'm getting "Cannot display summaries of variables with more than 524288 elements. "
Matt J
Matt J le 14 Déc 2013
Modifié(e) : Matt J le 14 Déc 2013
Well, it worked then, right? Use imshow or similar image display tool to inspect the image content.
Thanks anyway bro, I'll just use this:
clear
imgformat = 'LCC%d.jpg';
for k = 1:6
LCC{k} = imread(sprintf(imgformat, k));
cform = makecform('srgb2lab');
lab_Image{k} = applycform(LCC{k},cform);
LChannel{k} = lab_Image{k}(:, :, 1);
AChannel{k} = lab_Image{k}(:, :, 2);
BChannel{k} = lab_Image{k}(:, :, 3);
end

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by