鸡你太美警告!入门GUI。
读取图片按钮函数;
设置全局变量BW,后来调用非常方便。
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be definedina future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global BW
global filename
global pathname
[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像');
ifisequal(filename,0)|isequal(pathname,0)
errordlg('没有选中文件','出错');
return;
else
file=[pathname,filename];
end
BW = imread(file);
axes(handles.axes1);
imshow(BW);
title(date,'color','r');
保存图片按钮函数:
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%global BW
[filename,pathname]=...
uiputfile({'*.tif';'*.jpg';'*.png';'*.bmp'},'save pictrue');
if isequal(filename,0)||isequal(pathname,0)
return
else
str=[pathname filename]
axes(handles.axes2);
im=getimage(handles.axes2);
imwrite(im,str);
end
退出按钮函数:
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf) %关闭当前Figure窗口句柄
canny算子示例:
function radiobutton20_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton20
global BW;
global pathname;
global filename;
% axis off %%关闭坐标轴显示
str=[pathname filename];
%%打开图像
im=BW;
%%打开axes1的句柄 进行axes1的操作
axes(handles.axes1);
%%在axes1中显示 图像
imshow(im);
%图像处理部分
I=im2bw(im);
BW1=edge(I,'canny'); %用canny算子进行边缘检测
axes(handles.axes2);
imshow(BW1);
彩蛋