matlab批量修改圖片大小

轉自:http://blog.csdn.net/cike0cop/article/details/53087995
html

%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簡介:函數

函數功能:該函數用於對圖像作縮放處理。測試

調用格式:spa

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]);
相關文章
相關標籤/搜索