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
%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
相关文章推荐
- 毕业设计——人脸检测——004 学习别人代码——《matlab读取一个目录下的所有图片》
- matlab读取一个目录中所有文件的方法
- matlab把一个目录下的图片缩放到指定大小
- 把一个文件中所有文件名或者文件路径读取到一个txt文件,然后在matlab中读取
- matlab中怎样读取一个文件夹里面的指定类型的所有文件的名称?
- Android读取assets目录下的所有图片并显示的方法
- 一个小型的网站,比如个人网站,可以使用最简单的html静态页面就实现了,配合一些图片达到美化效果,所有的页面均存放在一个目录下,这样的网站对系统架构、性能的要求都很简单,随着互联网业务的不断丰富,网站
- matlab读取一个文件夹下的所有文件…
- 怎样用matlab读取一个文件夹下的多个子文件夹中的多个图片文件
- 如何用几行代码读取目录下所有的图片
- Matlab 关于如何读取文件夹中的所有图片(3种方法)
- 如何用几行代码读取目录下所有的图片
- 读取一个文件下的所有图片
- matlab 读取子文件夹下的所有图片
- 如何读取一个文件夹下的所有图像文件,并制作负样本到指定目录
- C++ 读取目录下的所有图片
- 如何用几行代码读取目录下所有的图片
- Java实现压缩一个目录下所有图片文件
- python 读取一个目录下的所有目录和文件
- MATLAB: 读取同一目录下的所有文件名并按时间排序