边缘检测的简单例子(MATLAB)

来源:互联网 发布:网络统考成绩查询2016 编辑:程序博客网 时间:2024/05/22 11:34

x = - 2 : 0.05: 2;
y = - 2 : 0.05: 2;
sigma = 0.5 ;
y = y';
for i = 1: ( 4 /0.05 + 1)
xx( i, : ) = x;
yy( : , i ) = y;
end
% 产生矩形网格
r = 1 / ( 2* pi* sigma^4) * ( ( xx.^2 + yy.^2 ) / ( sigma^2) - 2).* ...
exp( - ( xx.^2 + yy.^2 ) / ( 2 * sigma^2) ) ;
% 计算LoG 算子的值
colormap( jet( 16) ) ;
mesh( xx, yy, r)
% mesh 函数用于将函数值用三维网格显示

边缘检测
I = imread('eight.tif') ;
BW1 = edge( I, 'prewitt') ;
BW2 = edge( I, 'canny') ;
BW3 = edge( I, 'log') ;
subplot( 221) , imshow( I) , title( 'original image') ;
subplot( 222) , imshow( BW1) , title( 'prewitt') ;
subplot( 223) , imshow( BW2) , title( 'canny') ;
subplot( 224) , imshow( BW3) , title( 'laplacian') ;

http://zhidao.baidu.com/question/150295084.html

另外两种算法,
I = imread('black.jpg') ;
BW1 = edge( I(:,:,1), 'prewitt') ;
BW2 = edge( I(:,:,1), 'canny') ;
BW3 = edge( I(:,:,1), 'Sobel') ;
subplot( 221) , imshow( I) , title( 'original image') ;
subplot( 222) , imshow( BW1) , title( 'prewitt') ;
subplot( 223) , imshow( BW2) , title( 'canny') ;
subplot( 224) , imshow( BW3) , title( 'laplacian') ;