reading multiple images in a folder (imread)

Ok so I want to read 10 different images into matrices in Matlab. the images are saved as image001, image002 etc. up to image010. I tried this loop thinking it would work:
for n=1:10
image_{n}= imread(sprintf('image00%s.png',num2str(n)));
end
but it came up with the error:
??? Error using ==> strfind
Input strings must have one row.
Error in ==> imread at 340
if (strfind(filename, '://'))
it also would read the last image as image0010, which is not right. I then thought I could just do this:
for r= 1:10
sprintf('scan_%s', num2str(r)) = imread('*.png','png');
end
Because i thought that by putting "*.png" it would read all the images in the folder. But I go this error:
?? Error using ==> imread at 408
Can't open file "*.png" for reading;
you may not have read permission.
can someone see where I went wrong in my coding or suggest a better way to do it?
Thanks

댓글 수: 1

% I have the code that read only 4 images and show using subplot function. But can someone suggest me that how I show more then 4 images in matlab without subplot function.
clc;
clear all;
for i=1:4
FileName=uigetfile({'.'});
im=imread(FileName);
subplot(2,2,i);
imshow(im);
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 13일

2 개 추천

for n=1:10
images{n} = imread(sprintf('image%03d.png',n));
end
See also this FAQ and this one

댓글 수: 5

Jack Williams
Jack Williams 2011년 5월 13일
perfect so i assume the '%03d' makes 1 display as 001 and 10 010?
mohammad aluounis
mohammad aluounis 2020년 11월 5일
편집: mohammad aluounis 2020년 11월 5일
how can i acsess one of thes images after read it
@mohammad aluounis by calling its index.
images{1} for example is the image at index one in the cell array. This will give you the matrix of the image.
To see the actual image use
imshow(images{1})
And Allah knows best.
Take care bro.
atyaf hekmat
atyaf hekmat 2021년 11월 26일
Mr. @Mohammed Hammouda Can you help me make a code to read images from a folder with subfolders in which there are multiple images. I want to get its features by eucledean distance...with all of my thanks
@atyaf hekmat did you manage to figure out how to read images from a folder with subfolders by any chance?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 18일

0 개 추천

Your line
filename = strcat('E:\EXTRACT\Motorcycle\Pos*.jpg',srcFiles(i).name);
Should not have the 'Pos*.jpg' part of the string.
I recommend that you learn to use fullfile()

댓글 수: 1

hi i want to ask i am using the below code for reading multiple image but i want another folder to read the images in the same code how i modify this.i just want to read other folder not applying the same function for the second folder?
srcFile=dir('/MATLAB Drive/Published/*.bmp');
for i=1:length(srcFile)
filename=strcat('/MATLAB Drive/Published/', srcFile(i).name);
I=imread(filename);
im=rgb2gray(I);
path=strcat('/MATLAB Drive/Published/',srcFile(i).name);
imwrite(I,path);
end

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by