2012-02-15 63 views
0

我有使用imread命令由一個具有我想讀從文件夾中一個循環圖像的各種圖像的文件夾,任何建議如何做到這一點的最佳 感謝讀取圖像一個

+0

告訴我們你已經什麼試過。 – Oli 2012-02-15 20:41:49

+4

可能的重複[在MATLAB中加載多個圖像](http://stackoverflow.com/questions/2408112/loading-multiple-images-in-matlab) – yuk 2012-02-15 20:57:52

回答

0

您必須同步您的圖像名稱才能在循環中讀取。他們必須像image1.jpg,image2.jpg,image3.jpg ...你有10個像這樣的圖像。

NumberOfimages=10;  %chose the number of images you want to give input 
prefix_image='image'; %change the desired input image name here only 
fileformat='.jpg';  %change the desired input image format here only 

for num=1:NumberOfimages 
    image = imread(strcat(prefix_image,num2str(num),fileformat)); 
end 
+0

請不要在你的帖子中籤名。請參閱[常見問題#簽名]。 – Gilles 2012-02-18 18:32:54

1
  • 您可以使用dir函數獲取目錄中的所有文件。這將返回結構的載體,它也包括文件名
  • 遍歷所有的結構
  • 檢查文件是否是一個圖像(例如檢查擴展)
  • 讀取圖像
-1

這可以幫助您!

S = struct2cell(dir('*.jpg')); 
FileNames = S(1,:); 
lenDb = length(FileNames); 

result= struct('img', {}); 

for j = 1 : lenDb 


    result(j).img = imread(FileNames{j}) 
end 

所有的圖像都在結構 「result.img」

要訪問只需要調用的結果(NUM).IMG

例:

圖像(結果(1)。 img)

0

以及該功能將幫助您在一次甚至diferent名稱看了很多圖片:

首先把所有的圖片文件夾中,例如:d:/實驗室/

他們必須在本例同樣的格式:TIF

調用的函數,你鍵入:

A=imread_many(); 

個,所有的圖像將在變量A

,如果你想在第一圖像您鍵入A{1}如果u希望第二個U型A{2} ...等

function [ A ] = imread_many() 

    srcFiles = dir('D:\lab\*.tif'); % the folder in which ur images exists 
for i = 1 : length(srcFiles) 
    filename = strcat('D:\lab\',srcFiles(i).name); 
    A{i} = imread(filename); 
    figure, imshow(A{i}); 
end 

end 
0
srcFiles = dir('C:\Users\Omm\Downloads\multicharacterrec\*.png'); % the folder in which ur images exists 
for i = 1 : length(srcFiles) 
    filename = strcat('C:\Users\Omm\Downloads\multicharacterrec\',srcFiles(i).name); 
    I = imread(filename); 
    figure, imshow(I);