how to read multiple images from a folder

4 ビュー (過去 30 日間)
Tasneem Tabassum
Tasneem Tabassum 2017 年 4 月 5 日
編集済み: Stephen23 2017 年 4 月 5 日
I need to read multiple images from a folder in matlab. Meaning I need to read image number one and image number two in the first loop, in the second loop it will read read the second image and the third so on and so forth. currently what I'm trying is im using is given below. But it doesn't seem to work. What can I do so that i can read two consecutive images in the same loop?
Files = dir('......*.tif');
Directory='......';
for num=1:numberofimages
Image = imread(strcat(Directory,Files(num).name));
Nex_Image = imread(strcat(Directory,Files(num+1).name));
end

回答 (1 件)

Stephen23
Stephen23 2017 年 4 月 5 日
編集済み: Stephen23 2017 年 4 月 5 日
Something like this should get you started (obviously untested):
D = 'directory path here';
S = dir(fullfile(D,'*.tif'));
for k = 2:numel(S)
file1 = fullfile(D,S(k-1).name);
file2 = fullfile(D,S(k-0).name);
im1 = imread(file1);
im2 = imread(file2);
end
And if your filenames have numbers in them and you want them sorted alphanumerically, then download my FEX submission natsortfiles (it includes examples):
If these do not resolve your question then please explain exactly what you expect to occur, and what "But it doesn't seem to work" means.
  2 件のコメント
Tasneem Tabassum
Tasneem Tabassum 2017 年 4 月 5 日
Thanks a lot. It should work I suppose. But I was having issues in a different part of the code. Our logics are quite similar. Since mine is working atm i am sticking to that. But Thanks again for the response. :)
Image Analyst
Image Analyst 2017 年 4 月 5 日
Not sure what your definition of consecutive is, but you might take a look at this: http://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by