how to get a* and b* channel for entire leaf image .

1 回表示 (過去 30 日間)
Keerthi  D
Keerthi D 2020 年 8 月 24 日
コメント済み: Keerthi D 2020 年 10 月 1 日
I have a set of 1500 images of tomato leaf and i want to covert them from RGB to Lab( only need a*,b* channel),then i want to access and save a,b values for each images.
I tried some code.that is given below.but i get pnly the a,b value for one image.how to get entire images?please help me find that.
my code is,
fontSize=10;
location='C:\Users\Keerthi Dev\Downloads\dataset'; %folder in which your images exists
ds=imageDatastore(location); %create datastore for all images in your folder
new_folder='C:\Users\Keerthi Dev\Documents\MATLAB\leafdataset'; %new folder
k=1;
while hasdata(ds)
img=read(ds); %read image from datastore
scale=imresize(img,[256 256]);
fileName=sprintf('image_%d.jpg',k);
fullFileName=fullfile(new_folder,fileName);
imwrite(scale,fullFileName);
%size(scale)
k=k+1;
%lab conversion
labImage = rgb2lab(scale);
%a = labImage(:, :, 2);
subplot(1, 2, 1);
imshow(labImage(:, :, 2),[]);
title('A channel', 'FontSize' ,20);
%b = labImage(:, :, 3);
subplot(1, 2, 2);
imshow(labImage(:, :, 3),[]);
title('B channel', 'FontSize' ,20);
end
ouput is :
  2 件のコメント
Athul Prakash
Athul Prakash 2020 年 9 月 2 日
Hi Keerthi,
Your code does seem to iterate through all files correctly. I'm not sure why you are saving the images at the top of the loop body (after reading from datastore) before even converting to LAB format.
At the end of the loop body you are just displaying the values as well, so the 1500 A/B channels would only get displayed one by one. Further, I notice you're not saving the variable labImage; at the end of the loop, you would only be left with the last image you processed.
I think you should save the A/B channels as an array to a variable or, depending on what you want, save each instance of LAB as an image to you disk.
Hope it helps!
Keerthi  D
Keerthi D 2020 年 10 月 1 日
Can you please explain through the code sir.

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

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by