facing issue to show images from folder.

outputFolder = fullfile('caltech101');
rootFolder = fullfile(outputFolder,'ObjectCategories');
categories = {'airplanes','ferry','laptop'};
imds = imageDatastore(fullfile(rootFolder,categories),'LabelSource','foldernames','IncludeSubfolders',true);
tbl = countEachLabel(imds);
minSetCount = min(tbl{:,2});
imds = splitEachLabel(imds, minSetCount, 'randomize');
countEachLabel(imds)
airplanes = find(imds.Labels =='airplanes',1);
ferry = find(imds.Labels =='ferry',1);
laptop = find(imds.Labels =='laptop',1);
figure
subplot(2,2,1);
imshow(readimage(imds,airplanes));
subplot(2,2,2);
imshow(readimage(imds,ferry));
subplot(2,2,3);
imshow(readimage(imds,laptop));
ERROR:
Subscript indices must either be real positive
integers or logicals.
Error in classification (line 21)
imshow(readimage(imds,airplanes));

댓글 수: 1

You may need to use the MATLAB debugger to see what the values are for imds and airplanes. Is the latter a positive integer? Also, is this line of code
imds.Labels =='airplanes'
valid when comparing the labels with a string? Or do you need to use a strcmp?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 3월 31일
편집: Jan 2021년 3월 31일

0 개 추천

Use the debugger to find the cause of errors. Type this in the command window:
dbstop if error
Then run the code again. When Matlab stops at the error, check the values of the locally used variables. Here I guess, that you have redefined "readimage" by a variable:
which('readimage')
Geoff's idea is important also: The == operator works with string array, but not with char vectors. For the latter it is an elementwise comparison of the characters. Use strcmp instead.

카테고리

도움말 센터File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

질문:

2021년 3월 31일

편집:

Jan
2021년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by