雞你太美警告!入門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);
彩蛋