if isequal(filename,0) | isequal(pathname,0)
disp('User pressed cancel')
else
disp(['User selected ', fullfile(pathname, filename)])
end
imwrite(handles.imdata,filename);
guidata(hObject, handles);
5.3.4 关闭当前操作
只是关闭当前的操作,清楚前面的操作内容,运行结果如下图5.6所示
图5.6 关闭
相关代码如下:
function CloseFile_Callback(hObject, eventdata, handles)
% hObject handle to CloseFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=zeros(256);
axes(handles.axes1);
imshow(x);
axes(handles.axes2);
imshow(x);
set(handles.edit1,'string',0.0);
handles.imdata=zeros(256);
guidata(hObject, handles);
5.3.5 退出文件编辑
退出实现的功能就是退出程序的运行,使用MATLAB内置函数close即可实现。相关代码如下:
function EXIT_Callback(hObject, eventdata, handles)
% hObject handle to EXIT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
5.4 几何交换
5.4.1 图像的镜像变换
镜像变换是与人们日常生活密切相关的一种变换,图像的镜像(Mirror)变换不改变图像的形状。图像的镜像变换包括水平镜像、垂直镜像和对角镜像三种。图像的水平镜像变换是将图像左半部分和右半部分以图像垂直中轴线为中心进行镜像对称,如下图5.7所示。图像的垂直镜像变换是将图像上半部分和下半部分以图像水平中轴线为中心进行镜像对称,如下图5.8所示。
图5.7 水平镜像
水平镜像代码如下:
function HorizontalTransform_Callback(hObject, eventdata, handles)
tic;
x=handles.imdata; %设置水平镜像
[row,col]=size(x);
for i=1:row
for j=1:col
y(i,j)=x(i,col-j+1);
end
End
Time=toc; %计算运算时间
set(handles.edit1,'string',Time);
if (row<=256)&(row<=256)
W=256;
else
W=max(row,col);
end
extendx=double(zeros([W,W]));
for m=1:W
for n=1:W
if (m<=row)&(n<=col)
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.8 垂直镜像
实现垂直镜像的代码:
function VerticalTransform_Callback(hObject, eventdata, handles)
tic;
x=handles.imdata;
[M,N]=size(x);
for i=1:M
for j=1:N
y(i,j)=x(M-i+1,j);
end
end