How to display sequence of images in GUI

2 views (last 30 days)
Alex Grame
Alex Grame on 18 Jan 2022
Answered: yanqi liu on 19 Jan 2022
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

Answers (2)

Voss
Voss on 18 Jan 2022
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 on 19 Jan 2022
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!