How do I read multiple images into matlab and save them in cells?

2 ビュー (過去 30 日間)
Kenny Suh
Kenny Suh 2016 年 12 月 12 日
コメント済み: Kenny Suh 2016 年 12 月 12 日
So I have 10 images at the working directory(which is desktop) and named them as image1.jpg, image2.jpg, ... image10.jpg and I want to load into matlab and save them in cells. But apparently it saves the first image, but fails to do the same for the rest.
photo=cell(1,10);
for i=1:10
filename=['image',num2str(i),'.jpg'];
photo{i}=imread(filename);
end
and I get errors like:
Error using imread>get_full_filename (line 481) File "image2.jpg" does not exist.
Error in imread (line 344) filename = get_full_filename(fid, errmsg, filename);
Error in Untitled (line 5) photo{i}=imread(filename);
what should I do to make it work?
  2 件のコメント
Preethi
Preethi 2016 年 12 月 12 日
hi,
can you debug and see the filename or you can try reading the image2 file separately to check if there is any issue..
Kenny Suh
Kenny Suh 2016 年 12 月 12 日
Ugh, I checked if loading image2 worked separately. Apparently, it was the file format issue. The image2 file was .png format, not .jpg format. Thanks for reminding me of that! now it works :D

サインインしてコメントする。

採用された回答

Ahmet Cecen
Ahmet Cecen 2016 年 12 月 12 日
This is not directly solving your problem, but if you use the following instead, it will either work, or help you better figure out what the problem is:
jpglist = dir('*.jpg'); % Find all jpg files in current directory.
photo=cell(1,length(jpglist));
for i=1:length(jpglist)
photo{i}=imread(jpglist(i).name);
end
  1 件のコメント
Kenny Suh
Kenny Suh 2016 年 12 月 12 日
Thanks a lot. I've managed to solve the issue :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by