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