Displaying a set of images from a folder

11 ビュー (過去 30 日間)
Filip Juchnicki
Filip Juchnicki 2021 年 9 月 19 日
回答済み: Image Analyst 2021 年 9 月 19 日
Hello. I need to place a button in my app that displays all the images from a folder one after another with a time delay on a UIAxes and another button that opens a figure. I'm having problems with understanding the process behind opening files via code in matlab. Can anyone help me a bit in this matter?

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 19 日
編集済み: Walter Roberson 2021 年 9 月 19 日
projectdir = 'path/to/image/directory';
ext = '.png'; %adjust according to kind of images
dinfo = dir( fullfile( projectdir, "*"+ext) );
fullnames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(fullnames);
ax = app.axes1; %place you want the image to be shown
h = image(ax, []); %create image object with empty content
for K = 1 : nfiles
thisfile = fullnames{K};
[thisimg, thismap] = imread(thisfile); %handles pseudocolor and rgb both
h.CData = thisimg; %update the existing image object with the new image
if ~isempty(thismap); colormap(ax, thismap); end %if needed, update colormap
pause(0.2);
end
The above code does not, however, account for true grayscale images. You would detect those as thismap being empty and ndims(thisimg) is 2 .
  2 件のコメント
Filip Juchnicki
Filip Juchnicki 2021 年 9 月 19 日
Where is ext variable used?
Walter Roberson
Walter Roberson 2021 年 9 月 19 日
ext is used in
dinfo = dir( fullfile( projectdir, "*"+ext) );
So for example from .png it would construct the string "*.png" and that becomes the pattern that dir() is to search for -- files with that extension.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 19 日

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by