轉自:http://blog.csdn.net/cike0cop/article/details/53087995
%author:coplin
%time:2016-10-10
%function:change the size of Image.
addpath('dealImg');
addpath('Img');
ListName=dir('Img\*.jpg');
[Pm,Pn]=size(ListName);
for iPm=1:1:Pm %讀取文件夾所有圖片循環
oriImg=imread(ListName(iPm).name); %readImg
cutImg=imcrop(oriImg,[50,50,255,255]);
%bi=imresize(oriImg,0.6); %bi縮放為ai的0.6倍
%endImg=imresize(cutImg,[256,256]); %把ai轉成256x256的大小
iDealName=ListName(iPm).name;
iDealAddress='dealImg\';
iDealAll=strcat(iDealAddress,iDealName);
ID=imresize(cutImg,1);
imwrite(ID,iDealAll);
end 轉自:http://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
轉自:http://www.cnblogs.com/rong86/p/3558344.html
matlab中函數imresize簡介:
函數功能:該函數用於對圖像做縮放處理。
調用格式:
B = imresize(A, m)
返回的圖像B的長寬是圖像A的長寬的m倍,即縮放圖像。 m大於1, 則放大圖像; m小於1, 縮小圖像。
B = imresize(A, [numrows numcols])
numrows和numcols分別指定目標圖像的高度和寬度。 顯而易見,由於這種格式允許圖像縮放后長寬比例和源圖像長寬比例相同,因此所產生的圖像有可能發生畸變。
[...] = imresize(..., method)
method參數用於指定在改變圖像尺寸時所使用的算法,可以為以下幾種:
'nearest': 這個參數也是默認的, 即改變圖像尺寸時采用最近鄰插值算法;
'bilinear':采用雙線性插值算法;
'bicubic': 采用雙三次插值算法,在R2013a版本里,默認為這種算法,所以不同版本可能有不同的默認參數,使用之前建議使用命令help imresize獲得幫助信息,以幫助信息為准;
示例一
I = imread('rice.png');
J = imresize(I, 0.5);
figure, imshow(I), figure, imshow(J)
示例二
Shrink by factor of two using nearest-neighbor interpolation. (This is the fastest method, but it has the lowest quality.)
J2 = imresize(I, 0.5, 'nearest');
示例三
Resize an indexed image
[X, map] = imread('trees.tif');
[Y, newmap] = imresize(X, map, 0.5);
imshow(Y, newmap)
示例四
Resize an RGB image to have 64 rows. The number of columnsis computed automatically.
RGB = imread('peppers.png');
RGB2 = imresize(RGB, [64 NaN]);
