并行边缘检测

来源:互联网 发布:族谱排版软件 编辑:程序博客网 时间:2024/06/10 11:48

基本原理

一阶微分算子(即梯度算子)利用灰度一阶导数的信息完成幅图像边缘的检测。代表Roberts,Kirsch,Prewitt,Sobel,Isotropic Sobel,Robinson,Frei,Chen等。

计算一阶梯度,选取阀值,灰度梯度幅值大于阀值处点作为阶跃状边缘点检出。

计算幅值常用近似方法:

|f|=|Gx|+|Gy|

|f|=max(|Gx|,|Gy|)

常见模版

  • Roberts

    Gx=f(x+1,y+1)f(x,y)

    Gy=f(x,y+1)f(x+1,y)

    模版
    [1001]

    [0110]

  • Prewitt
    模版

    111000111

    101101101

  • Sobel
    模版

    121000121

    101202101

    45度模版
    210101012

    135度模版
    012101210

  • Istropic Sobel
    模版

    121000121

    101202101

code

clear allload ('lena512.mat');pic=uint8(lena512);prewitt_x=[-1,0,1;-1,0,1;-1,0,1];prewitt_y=[-1,-1,-1;0,0,0;1,1,1];sobel_x=[-1,0,1;-2,0,2;-1,0,1];sobel_y=[-1,-2,-1;0,0,0;1,2,1];threshold=70;prewitt=cal_derivatives(prewitt_x,prewitt_y,pic,threshold);sobel=cal_derivatives(sobel_x,sobel_y,pic,threshold);subplot(131)imshow(pic)title('original image')subplot(132)imshow(prewitt)title('prewitt')subplot(133)imshow(sobel)title('sobel')function [pic_xy]=cal_derivatives(temp_x,temp_y,pic,threshold)[mx,~]=size(temp_x);mid=(mx-1)/2;[m,n]=size(pic);pic=double(pic);for i=1+mid:m-mid    for j=1+mid:n-mid        pic_x(i,j)=abs(sum(sum(pic(i-mid:i+mid,j-mid:j+mid).*temp_x)));        pic_y(i,j)=abs(sum(sum(pic(i-mid:i+mid,j-mid:j+mid).*temp_y)));    endendpic_xy=zeros(m,n);% pic_xy=pic_x+pic_y;pic_xy=max(pic_x,pic_y);pic_xy(pic_xy<threshold)=0;pic_xy(pic_xy>=threshold)=255;pic_xy=uint8(pic_xy);end

edge detection

原创粉丝点击