Reading multiple images from a folder in MATLAB Directory

I need to read several images from a folder in MATLAB Directory, in order to do several operations on it, I have written the following code:
Directory = fullfile ('C:','Users','ssr729','Documents','MATLAB','image');
Images = dir(fullfile(Directory,'*.jpg'));
Names = {Images.name}';
for k=1: numel(Names)
I = imread(Names{k});
%operations
end
I am receiving this error and I do not know why:
Error using imread (line 372)
File "polymerc.jpg" does not exist.
Even though the image 'polymera.jpg' does exist in the specified path. Any help is really appreciated. Thanks

 채택된 답변

F.
F. 2012년 7월 10일
you lost the path ...
try:
imread( fullfile( Directory, Names{k} ) )

댓글 수: 4

I getting a similar error: for k=1: numel(Names) I = imread(fullfile(Directory,Names{k})); end Error using imread (line 372) File "C:\Users\ssr729\Documents\MATLAB\image\polymera.jpg" does not exist. However when I changed the Directory to : "C:\Users\ssr729\Documents\image\polymera.jpg" it worked. Do you have any idea why?
could you check your file before read it ??
if exist( ....
imread(fullfile(Directory,Names{k}));
else
error( ...
end
Thank you F.
Well, apparently the images live in the C:\Users\ssr729\Documents\image folder and not the C:\Users\ssr729\Documents\MATLAB\image folder. It will work if it looks in the right folder, and it won't work if it looks in the wrong folder - makes sense?

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

추가 답변 (1개)

Thomas
Thomas 2012년 7월 10일
Your error states that
Error using imread (line 372) File "polymerc.jpg" does not exist.
Even though the image 'polymera.jpg' does exist in the specified path
Notice the difference between ploymerc and polymera The two files are different..
Also please go through the following which might help

댓글 수: 1

Thanks Binish for pointing this out, but in the folder I have the two images '*polymera*' and '*polymerc*' and still I have the mentioned error above.

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

카테고리

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

질문:

2012년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by