facing issue to show images from folder.
Ältere Kommentare anzeigen
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 Kommentar
Geoff Hayes
am 31 Mär. 2021
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?
Antworten (1)
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.
Kategorien
Mehr zu Image Processing and Computer Vision finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!