How to display sequence of images in GUI

4 ビュー (過去 30 日間)
Alex Grame
Alex Grame 2022 年 1 月 18 日
回答済み: yanqi liu 2022 年 1 月 19 日
Hi, I have sequence of images in a folder. I have created a very simple GUI with "LOAD DATASET" push button. I want to show the images as a sequence in GUI when i select the dataset folder. GUI screen and code is attached here for your kind consideration. I have images in :
"C:\Users\reala\Desktop\Tracker GUI\Surfer\imgs"
Thank you
code is:
path = uigetdir();
img_path = [path '/imgs/'];
D = dir([img_path, '*.jpg']);
seq_len = length(D(not([D.isdir])));
if exist([img_path num2str(1, '%04i.jpg')], 'file'),
img_files = num2str((1:seq_len)', [img_path '%04i.jpg']);
else
error('No image files found in the directory.');
end
for i=1:size(img_files,1)
img = imread(img_files(i, :));
imshow(img);
end

回答 (2 件)

Voss
Voss 2022 年 1 月 18 日
This line:
img_files = num2str((1:seq_len)', [img_path '%04i.jpg']);
should be like this:
img_files = strcat(img_path,num2str((1:seq_len)','%04i.jpg'));

yanqi liu
yanqi liu 2022 年 1 月 19 日
path = uigetdir();
img_path = [path '/imgs/'];
D = dir([img_path, '*.jpg']);
seq_len = length(D(not([D.isdir])));
img_files = [];
if exist([img_path num2str(1, '%04i.jpg')], 'file')
img_files{end+1} = num2str((1:seq_len)', [img_path '%04i.jpg']);
else
error('No image files found in the directory.');
end
for i=1:length(img_files)
img = imread(img_files{i});
axes(handles.axes1); cla;
imshow(img);
pause(1);
end

Community Treasure Hunt

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

Start Hunting!

Translated by