How to read multiple .png images in a loop using MATLAB

9 次查看(过去 30 天)
I want to display multiple picture with using for loop. Maximum 200 picture need to display. I'm doing my code like this:
numberArray = [];
for i = 1:200
str = int2str(i);
str = strcat('\',str,'.png');
str = strcat('C:\Users\Hasibur Rahman\Documents\MATLAB\ClassWork2_62018040032_哈西\LFPW\trainset', str);
image = imread(str);
numberArray = image;
numberArray = numberArray + image;
figure,imshow(numberArray);
title('Original Image!');
pause(1.5);
end
The first picture came to the display then nothing else comes. Now what i need to do to solve that problem. Thanks in advance.
Error using imread>get_full_filename (line 567)
File "C:\Users\Hasibur Rahman\Documents\MATLAB\ClassWork2_62018040032_哈西\2.png" does not exist.
Error in imread (line 374)
fullname = get_full_filename(filename);
Error in Ques3 (line 6)
im = imread(str);

采纳的回答

Mathieu NOE
Mathieu NOE 2020-10-14
hi
see below - just change from tif to png extesion and you should be good !
% select appropriate options below ...
% files = dir('*.tif'); % all tif files in current directory
files = dir('handheld*.tif'); % as example : only tiff files with "handheld" in the filename
% main loop
for ck = 1:length(files)
Filename = files(ck).name;
H{ck} = imread(Filename);
% plot (t=just to check)
figure(ck), imagesc(H{ck});
% insert your own code here
end

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by