2013-04-05 61 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'])];