Time=toc;
set(handles.edit1,'string',Time);
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
extendx=double(zeros([W,W]));
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=y(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[min(min(y)),max(max(y))]);
handles.imdata=y;
guidata(hObject, handles);
图5.9 旋转后的图像与原图像的对比
实现图像旋转的主要到吗如下:
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.3 图像平移