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 件のコメント

Geoff Hayes
Geoff Hayes 2021 年 3 月 31 日
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 ExchangeImage 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