【正文】
nction m_file_exit_Callback(hObject, eventdata, handles)close()。% hObject handle to m_file_exit (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % function m_image_Callback(hObject, eventdata, handles)% hObject handle to m_image (see GCBO)26% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % function m_sobel_Callback(hObject, eventdata, handles)axes()。%用axes命令設(shè)定當(dāng)前操作的坐標軸是axes_src img_src=getappdata(,39。img_src39。)。A=img_src。axes()。imshow(A)。title(39。原圖39。)。y_mask = [1 2 1。0 0 0。1 2 1]。 % 建立Y方向的模板x_mask = y_mask39。 % 建立X方向的模板I = im2double(A)。 % 將圖像數(shù)據(jù)轉(zhuǎn)化為雙精度dx = imfilter(I, x_mask)。 % 計算X方向的梯度分量dy = imfilter(I, y_mask)。 % 計算Y方向的梯度分量grad = sqrt(dx.*dx + dy.*dy)。 % 計算梯度grad = mat2gray(grad)。 % 將梯度矩陣轉(zhuǎn)換為灰度圖像level = graythresh(grad)。 % 計算灰度閾值axes()。BW = im2bw(grad,level)。 % 用閾值分割梯度圖像imshow(BW)。 % 顯示分割后的圖像即邊緣圖像title(39。Sobel39。)% hObject handle to m_sobel (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) 27% function m_Roberts_Callback(hObject, eventdata, handles)img_src=getappdata(,39。img_src39。)。A=img_src。axes()。imshow(A)。title(39。原圖39。)。x_mask = [1 0。0 1]。 % 建立X方向的模板y_mask = rot90(x_mask)。 % 建立Y方向的模板I = im2double(A)。 % 將圖像數(shù)據(jù)轉(zhuǎn)化為雙精度dx = imfilter(I, x_mask)。 % 計算X方向的梯度分量dy = imfilter(I, y_mask)。 % 計算Y方向的梯度分量grad = sqrt(dx.*dx + dy.*dy)。 % 計算梯度grad = mat2gray(grad)。 % 將梯度矩陣轉(zhuǎn)換為灰度圖像level = graythresh(grad)。 % 計算灰度閾值axes()。BW = im2bw(grad,level)。 % 用閾值分割梯度圖像imshow(BW)。 % 顯示分割后的圖像即邊緣圖像title(39。Roberts39。)% hObject handle to m_Roberts (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % function m_priwitt_Callback(hObject, eventdata, handles)img_src=getappdata(,39。img_src39。)。A=img_src。28axes()。imshow(A)。title(39。原圖39。)。y_mask = [1 1 1。0 0 0。1 1 1]。 % 建立Y方向的模板x_mask = y_mask39。 % 建立X方向的模板I = im2double(A)。 % 將圖像數(shù)據(jù)轉(zhuǎn)化為雙精度dx = imfilter(I, x_mask)。 % 計算X方向的梯度分量dy = imfilter(I, y_mask)。 % 計算Y方向的梯度分量grad = sqrt(dx.*dx + dy.*dy)。 % 計算梯度grad = mat2gray(grad)。 % 將梯度矩陣轉(zhuǎn)換為灰度圖像level = graythresh(grad)。 % 計算灰度閾值axes()。BW = im2bw(grad,level)。 % 用閾值分割梯度圖像imshow(BW)。 % 顯示分割后的圖像即邊緣圖像title(39。Prewitt39。)% hObject handle to m_priwitt (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % function m_lapacian_Callback(hObject, eventdata, handles)img_src=getappdata(,39。img_src39。)。A=img_src。axes()。imshow(A)。title(39。原圖39。)。 mask=[0,1,0。1,4,1。0,1,0]。 % 建立模板I = im2double(A)。 % 將數(shù)據(jù)圖像轉(zhuǎn)化為雙精度dx = imfilter(I, mask)。 % 計算梯度矩陣29grad = mat2gray(dx)。 % 將梯度矩陣轉(zhuǎn)化為灰度圖像axes()。BW = im2bw(grad,)。 % 用閾值分割梯度圖像imshow(BW)。 % 顯示分割后的圖像,即梯度圖像title(39。Laplacian39。)% hObject handle to m_lapacian (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % function m_canny_Callback(hObject, eventdata, handles)img_src=getappdata(,39。img_src39。)。I=img_src。axes()。imshow(I)。title(39。原圖39。)。I=rgb2gray(I)。axes()。BW = edge(I,39。canny39。)。 % 調(diào)用canny函數(shù) imshow(BW)。 % 顯示分割后的圖像,即梯度圖像 title(39。canny39。)。% hObject handle to m_canny (see GCBO)% eventdata reserved to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)