フィルターのクリア

How to read and display multiple images in matlab

2 ビュー (過去 30 日間)
DSB
DSB 2017 年 3 月 10 日
編集済み: Image Analyst 2017 年 3 月 10 日
Hi there
I'm trying to read an images from the folder using for loop but when i run the code it doesn't work
Here is my code:
folder='Documents/MATLAB/*.png' ;
I=dir(fullfile(folder,'*.png'));
for k=1:numel(I)
filename=fullfile(folder,I(k).name);
a=imread(filename);
end

回答 (3 件)

Adam
Adam 2017 年 3 月 10 日
Your code is equivalent to:
fullfile( 'Documents/MATLAB/*.png', '*.png' );
which is clearly not going to resolve to something sensible. dir just needs a folder given to it, not filenames with extensions.
  2 件のコメント
Guillaume
Guillaume 2017 年 3 月 10 日
編集済み: Guillaume 2017 年 3 月 10 日
Well, actually in R2016b, the above would be a valid string to pass to dir. However, it is extremely unlikely to find anything and is most certainly not what is intended.
It would find all files and folders ending in .png in all immediate subfolders of Documents/MATLAB/ ending in .png. While windows allows dots in folder names, it's an unusual thing to do.
Adam
Adam 2017 年 3 月 10 日
Useful to know. I've only used dir on folders so far!

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


Thorsten
Thorsten 2017 年 3 月 10 日
編集済み: Thorsten 2017 年 3 月 10 日
Try
folder='Documents/MATLAB/';

Image Analyst
Image Analyst 2017 年 3 月 10 日
編集済み: Image Analyst 2017 年 3 月 10 日
Like Adam said, see the FAQ for two code samples: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
A glaring problem with your code is the lack of any way to show/display the images. There is no imshow(a) in your loop. Other problems include no using "drawnow" to see the images after each one, otherwise you'll just see the last images. And using horrible variable names like the badly-named a.
See attached demo.

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by