⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edge_detect.m

📁 从MatlabSimulink模型到代码实现
💻 M
字号:
function [BW1,BW2]=edge_detect(filename)
%EDGE_DETECT Detect the edge of input image
%This function takes an intensity image I as its input,
%and plots and return two binary images BW of the same 
%size as I,with 1's where the function finds edges in
%I and 0's elsewhere with Sobel and Canny method.
I = imread(filename);

%The Sobel method finds edges using the Sobel approximation
%to the derivative. It returns edges at those points where
%the gradient of I is maximum.
BW1 = edge(I,'sobel');

%The Canny method finds edges by looking for local maxima of
%the gradient of I. The gradient is calculated using the
%derivative of a Gaussian filter. The method uses two thresholds,
%to detect strong and weak edges, and includes the weak edges
%in the output only if they are connected to strong edges. This
%method is therefore less likely than the others to be "fooled"
%by noise, and more likely to detect true weak edges.
BW2 = edge(I,'canny');

figure;
subplot(1,2,1);
imshow(I);
title(['original ',filename]);
subplot(1,2,2);
imshow(BW1);
title(['edge\_detected ',filename,' with ''soble'' method']);

figure;
subplot(1,2,1);
imshow(I);
title(['original ',filename]);
subplot(1,2,2);
imshow(BW2);
title(['edge\_detected ',filename,' with ''canny'' method']);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -