https://blog.csdn.net/wuzuyu365/article/details/78215268


%把一个目录下的图片缩放到指定大小
dpath = 'D:\tst测试工作\测试文件\清晰照片库1300张';
lst = dir(dpath);
cnt = 0; 
for i=1:length(lst)
    if isdir(lst(i).name)
        continue; 
    end 
    tpath = [lst(i).folder,'\', lst(i).name];
    im=imread(tpath); 
    [m,n,c]=size(im); 
    if m < 1 || n < 1
        fprintf('bad image, %s\n', tpath); 
        continue;
    end 
    if m<500 || n<500 
        cnt = cnt+1;
         fprintf('%d, small image,(%d,%d), %s\n', cnt, m,n, tpath); 
        x= min(m,n);
        ratio = 505 / x; 
        im=imresize(im, ratio);  
        imwrite(im, tpath); 
    end     
end 
--------------------- 
作者:wuzuyu365 
来源:CSDN 
原文:https://blog.csdn.net/wuzuyu365/article/details/78215268 
 

转 matlab 图片批量 缩放尺寸

 

相关文章: