图5.11 平移后的图像
实现图像平移的主要代码如下:
function ImageRotate_Callback(hObject, eventdata, handles)
tic;
x=handles.imdata;
prompt={'Angle(-360~360):'};
name='Input for Geometric Transformation';
numlines=1;
defaultanswer={'45'};
anss=inputdlg(prompt,name,numlines,defaultanswer);
theta=str2num(anss{1});
T=[cos(theta) sin(theta) 0;-sin(theta) cos(theta) 0;0 0 1];
tform=maketform('affine',T);
g=imtransform(x,tform);
Time=toc;
set(handles.edit1,'string',Time);
[row,col]=size(g);
if (row<=256)&(col<=256)
for m=1:256
for n=1:256
if (m<=row)&(n<=col)
extendx(m,n)=g(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[]);
else
M=max(row,col);
for m=1:M
for n=1:M
if (m<=row)&(n<=col)
extendx(m,n)=g(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[]);
msgbox('The output image has a width or height larger than 256!','HELP','help');
end
handles.imdata=g;
guidata(hObject, handles);
5.4.4 图像缩放
在图像的缩小操作中,是在现有的信息里如何挑选所需要的有用信息,而在图像放大操作中,则需要对尺寸放大后所多出来的空格填入适当的像素值。图像缩小后和原图对比,如下图5.12所示