www.gusucode.com > matlab编写的图像几何变换的程序源码 > imscale.m
function [mat_ref_new, mat_m_new]=imscale(mat_ref, mat_m, s) %Revised image scaling function with proper resize such that the input and %output will have the same size. Input: double image Output: double image %confirmed! [mo,no]=size(mat_ref); m=round(mo/s); n=round(no/s); %四舍五入取整 mat_scaled=imresize(mat_m, [m n], 'bicubic'); if mo>=m && no>=n mat_ref_new=mat_ref; mat_m_new=zeros(mo, no); %floor 向下取整 mat_m_new((floor(mo/2)-floor(m/2)+1):(floor(mo/2)-floor(m/2)+m), ... ((floor(no/2)-floor(n/2)+1):(floor(no/2)-floor(n/2)+n)))=mat_scaled; else mat_ref_new=zeros(m, n); mat_m_new=mat_scaled; mat_ref_new((floor(m/2)-floor(mo/2)+1):(floor(m/2)-floor(mo/2)+mo), ... (floor(n/2)-floor(no/2)+1):(floor(n/2)-floor(no/2)+no))=mat_ref; end end