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

Matlab 文件夹遍历并更改图片尺寸

2015-08-29 16:26 357 查看

关键词

dir

code

function imageReshape()
% reshape objects to 384 x 256 or 256 x 384 so can be use in ImageRetrieval

src='D:\Program\matlab\bgslibrary_mfc\dataset\objects';
des='D:\Program\matlab\ImageRetrieval\objects';
% layernum=3;
len1=384;
len2=256;
pathlist1=dir(src);
filenum1=length(pathlist1);
filenamelist1={pathlist1.name};

filenum1=min(filenum1,1000);
for i=3:filenum1
imgsrcpath=[src,'\',filenamelist1{i}];
%     imgdespath=[des,'\',int2str(i),'.png'];
imgdespath=[des,'\',filenamelist1{i}];
imgsrc=imread(imgsrcpath);
[width,height]=size(imgsrc);
if(width>height)
%row=width=len1, col=height [row,col]=[width,height]
imgdes=imresize(imgsrc,[len1,len2]);
imwrite(imgdes,imgdespath);
else
imgdes=imresize(imgsrc,[len2,len1]);
imwrite(imgdes,imgdespath);
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: