您的位置:首页 > 编程语言 > MATLAB

tips:matlab读取一个目录下的所有图片

2011-03-30 14:23 232 查看
%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)
if nargin<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
for i=1:filenum
%ignore two special files: current catalog and father catalog
if strcmp(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
if grayflag==1
tempcount=size(imglist);
for j=1:tempcount(2)
imglist{j}=rgb2gray(imglist{j});
end
end

下载地址:http://download.csdn.net/source/3141370
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐