MATLAB批量改變圖片大小
阿新 • • 發佈:2019-01-02
參考: 點選開啟連結%2018年6月28日11:07:15 %把一個目錄下的圖片縮放到指定大小 clc clear ratio = 0.2;%縮放比例 cd('F:\資料集\crumpled clothes\cloth3\original image\');%不加這句話找不到圖片 dpath = 'F:\資料集\crumpled clothes\cloth3\original image\*.JPG';%找到路徑下所有格式為.JPG的檔案 spath = 'F:\資料集\crumpled clothes\cloth3\original image';%存放修改後的圖片 file = dir(dpath); cnt = 0; for i=1:length(file) tpath = [spath,'\folder\', file(i).name];%修改後的存放路徑 name = file(i).name; im = imread(name); [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); im = imresize(im, ratio); imwrite(im, tpath); end end