【邊緣檢測】基于sobel、prewit、canny算法實(shí)現(xiàn)圖像邊緣檢測含Matlab源碼
1 簡介
圖像邊緣是圖像的最基本的特征.所謂邊緣,就是指圖像局部強(qiáng)度變化最明顯的部分,存在于區(qū)域與區(qū)域,目標(biāo)與目標(biāo),目標(biāo)與背景,基元與基元之間,包含有圖像處理中用于識(shí)別的關(guān)鍵信息.邊緣檢測是數(shù)字圖像處理中,最基礎(chǔ)也是最重要的環(huán)節(jié)之一. 本文介紹了3種經(jīng)典的邊緣檢測算子,包括Sobel算子,Canny算子,Prewitt算子檢測方法.并且利用MATLAB系統(tǒng)所提供的相關(guān)函數(shù)等,對(duì)同一副圖像結(jié)合用這些不同的算子分別進(jìn)行處理,分析并得到他們處理圖像的特點(diǎn).?
2 部分代碼
function varargout = guipic(varargin)
% GUIPIC MATLAB code for guipic.fig
% ? ? ?GUIPIC, by itself, creates a new GUIPIC or raises the existing
% ? ? ?singleton*.
%
% ? ? ?H = GUIPIC returns the handle to a new GUIPIC or the handle to
% ? ? ?the existing singleton*.
%
% ? ? ?GUIPIC('CALLBACK',hObject,eventData,handles,...) calls the local
% ? ? ?function named CALLBACK in GUIPIC.M with the given input arguments.
%
% ? ? ?GUIPIC('Property','Value',...) creates a new GUIPIC or raises the
% ? ? ?existing singleton*. ?Starting from the left, property value pairs are
% ? ? ?applied to the GUI before guipic_OpeningFcn gets called. ?An
% ? ? ?unrecognized property name or invalid value makes property application
% ? ? ?stop. ?All inputs are passed to guipic_OpeningFcn via varargin.
%
% ? ? ?*See GUI Options on GUIDE's Tools menu. ?Choose "GUI allows only one
% ? ? ?instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help guipic
% Last Modified by GUIDE v2.5 13-Mar-2021 17:27:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', ? ? ? mfilename, ...
? ? ? ? ? ? ? ? ? 'gui_Singleton', ?gui_Singleton, ...
? ? ? ? ? ? ? ? ? 'gui_OpeningFcn', @guipic_OpeningFcn, ...
? ? ? ? ? ? ? ? ? 'gui_OutputFcn', ?@guipic_OutputFcn, ...
? ? ? ? ? ? ? ? ? 'gui_LayoutFcn', ?[] , ...
? ? ? ? ? ? ? ? ? 'gui_Callback', ? []);
if nargin && ischar(varargin{1})
? ?gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
? ?[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
? ?gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before guipic is made visible.
function guipic_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject ? ?handle to figure
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
% varargin ? command line arguments to guipic (see VARARGIN)
% Choose default command line output for guipic
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guipic wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = guipic_OutputFcn(hObject, eventdata, handles)
% varargout ?cell array for returning output args (see VARARGOUT);
% hObject ? ?handle to figure
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in ok.
function ok_Callback(hObject, eventdata, handles)
% hObject ? ?handle to ok (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
global im
%選擇圖片路徑
[filename,pathname]=...
? ?uigetfile({'*.jpg';'*.bmp';'*.gif'},'選擇圖片');
%合成路徑加文件名
str=[pathname filename];
%讀取圖片
im=imread(str);
%使用第一個(gè)AXES
axes(handles.axes1);
%顯示圖片
imshow(im);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject ? ?handle to pushbutton2 (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
close(gcf)
3 仿真結(jié)果

4 參考文獻(xiàn)
[1]吳曦. 基于MATLAB的圖像邊緣檢測算法的研究和實(shí)現(xiàn)[D]. 吉林大學(xué).
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號(hào)處理、元胞自動(dòng)機(jī)、圖像處理、路徑規(guī)劃、無人機(jī)等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。
