zl程序教程

您现在的位置是:首页 >  后端

当前栏目

matlab批量修改图片大小

MATLAB批量 修改 图片大小
2023-09-14 08:58:46 时间

转自: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]);