フィルターのクリア

Assigning values to images in an imageset

3 ビュー (過去 30 日間)
Pranaya Kansakar
Pranaya Kansakar 2020 年 5 月 12 日
回答済み: Ameer Hamza 2020 年 5 月 12 日
I read an imageset as such:
imgset = imageSet('dataset');
a1 = read(imgset,1);
a2 = read(imgset,2);
a3 = read(imgset,3);
Where i create a new variable that corresponds to each image in a dataset.
Is there an automated way that i can do this (create new variables into the workspace) for the duration of the imageset (ie imgset.Count)?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 12 日
You should try to avoid dynamic variables names like a1, a2, ... and use arrays. Read here why: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
For example, here you can use cell arrays
imgset = imageSet('dataset');
imgs = cell(1, imgset.Count);
for i=1:numel(imgs)
imgs{i} = read(imgset, i);
end
and then you can access the image using brace indexing
imshow(imgs{1});
imshow(imgs{2});

その他の回答 (0 件)

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by