假如读取F盘English文件夹中的所有bmp图片:
Files = dir(strcat('F:\\english\\','*.bmp'));
LengthFiles = length(Files);
for i = 1:LengthFiles;
Img = imread(strcat('F:\english\',Files(i).name));
%自己写图像处理函数 ImgProc(Img);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
from: http://blog.csdn.net/warmyellow/article/details/6288670
%this function is used to batch read the image datas from rootpath
%the var imglist is a cell which contain the image datasets.
%the var rootpath is the path of directory
%the var grayflag means: do you want to translate the raw image to gray
%image. if grayflag is 1 that means yes,otherwise means no
%rootpath='E:/pedestrain datasets/MIT_pedestrians128x64/dataset1';
function[imglist]=BatchReadImg(rootpath,grayflag)
ifnargin<2
disp('Not enough parameters!');
return;
end
filelist=dir(rootpath);%get the filelist from rootpath
[filenum,temp]=size(filelist);%get the filelist's count
tempind=0;
imglist=cell(0);%define the var of imagedata list
fori=1:filenum
%ignore two special files: current catalog and father catalog
ifstrcmp(filelist(i).name,'.')|| strcmp(filelist(i).name,'..')
%do nothing
else
tempind=tempind+1;%count for picture
imglist{tempind}=imread(strcat(rootpath,'/',filelist(i).name));
end
end
%rgb2gray
ifgrayflag==1
tempcount=size(imglist);
forj=1:tempcount(2)
imglist{j}=rgb2gray(imglist{j});
end
end