2013-04-05 56 views
1

我有一段代碼圖像格式

imgPath = 'F:\SIFT\images\'; 
dCell = dir([imgPath '*.jpg']); 

在這裏,我打開一個目錄,並獲得在DCELL類型JPG,但我真正想要的所有圖像的列表不只是JPG,但甚至其他圖像格式,如PNG或TIFF等等,都可以考慮...請幫助!謝謝

回答

0

假設你的文件夾,F:\SIFT\images\只包含必要的圖像文件,你可以簡單地使用:

imgPath = 'F:\SIFT\images\'; %Specifies the directory path as a string. 
dCell = dir(imgPath); %Gets all entries in the directory; similar to `dir` command in Windows or the `ls` command in linux. 

%By default, the first two output entries of `dir` are `.` and `..` which refer to the current and parent directories respectively. 
dCell = dCell(3:end); %Eliminates the default dir entries `.` and `..` by truncating the first two array elements. 

現在日e結果可以訪問爲:

dCell(1) %Entry corresponding to the first file. 
dCell(2) %Entry corresponding to the second file. 

等等。

dCell每個輸出條目是struct具有以下字段:

name 
date 
bytes 
isdir 
datenum 

得到各個領域,用途:

dCell.name 

等。

爲了得到一個特定的輸出struct的各個領域,用途:

dCell(1).name 
dCell(3).date 

等。

欲瞭解更多相關信息,您可以嘗試help dirhelp struct

+0

可以請你解釋一下我的代碼...我對matlab沒什麼興趣 – aushima 2013-04-05 07:11:07

+0

@aushima:好的。我會發表評論。 – 2013-04-05 07:15:23

+0

plz編輯答案...謝謝! – aushima 2013-04-05 07:17:25

0

我認爲你必須建立自己的數組:

imgPath = 'F:\SIFT\images\'; 
dCell = dir([imgPath '*.jpg']); 
dCell = {dCell; dir([imgPath '*.gif'])}; 
dCell = {dCell; dir([imgPath '*.jpg'])}; 
%etc... 

我不是,如果上面的應該是[]{} 100%,即可能是dCell = [dCel; dir([imgPath '*.gif'])];