在用Matlab对图像进行处理时经常需要获取文件夹下的图像文件名,有两个方法可采用:
1、没用存储图像名字的txt文件,使用dir命令,例如:
all_imgs=dir(['weiminghu/' '*.jpg']);
获取的是weiminghu文件夹下的所有jpg文件的文件名,all_imgs中的每一个数据是一个结构体
structure with the fields:
name -- Filename
date -- Modification date
bytes -- Number of bytes allocated to the file
isdir -- 1 if name is a directory and 0 if not
datenum -- Modification date as a MATLAB serial date number.
This value is locale-dependent.
2、在list.txt中存有图像的名字
all_imgs=importdata('hongsilou/list.txt');
all_imgs是一个cell数组,每个cell中存的是图像的名字