1

我有一段代码

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

在这里,我打开一个目录并获取 dCell 中所有 jpg 类型的图像的列表,但我真正想要的不仅仅是 jpg,甚至是其他图像格式,如 png 或 tiff 等要考虑...请帮助!谢谢

4

2 回答 2

0

我认为您必须自己构建数组:

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

[]如果以上内容应该在or中,我不是 100% {},即可能是dCell = [dCel; dir([imgPath '*.gif'])];

于 2013-04-05T06:38:19.270 回答
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.

现在可以通过以下方式访问结果:

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

于 2013-04-05T07:05:06.053 回答