雞你太美警告线脚!入門GUI搓劫。
讀取圖片按鈕函數(shù);
設(shè)置全局變量BW畅买,后來(lái)調(diào)用非常方便。
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('沒(méi)有選中文件','出錯(cuò)');
return;
else
file=[pathname,filename];
end
BW = imread(file);
axes(handles.axes1);
imshow(BW);
title(date,'color','r');
保存圖片按鈕函數(shù):
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
退出按鈕函數(shù):
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)? %關(guān)閉當(dāng)前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? %%關(guān)閉坐標(biāo)軸顯示
str=[pathname filename];
%%打開(kāi)圖像
im=BW;
%%打開(kāi)axes1的句柄 進(jìn)行axes1的操作
axes(handles.axes1);
%%在axes1中顯示 圖像
imshow(im);
%圖像處理部分
I=im2bw(im);
BW1=edge(I,'canny'); %用canny算子進(jìn)行邊緣檢測(cè)
axes(handles.axes2);
imshow(BW1);
彩蛋