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 comentario

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?

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 31 de Mzo. de 2021
Editada: Jan el 31 de Mzo. de 2021
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.

Categorías

Más información sobre Image Processing and Computer Vision en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Mzo. de 2021

Editada:

Jan
el 31 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by