Edge detection method -- first-order edge detection

Table of contents

Summary

Basic operator of first order edge detection (First Order Edge Detection)

Improved first-order edge detection

Rorberts cross operator

Prewitt edge detection operator 

Sobel detection operator:


First Order Edge Detection

Summary

The analysis based on edge detection is not easily affected by the change of the overall light intensity, and the edge detection emphasizes the image contrast, that is, the difference in brightness. To detect the edge position, we can first apply the first order differentiation, because the first order differentiation can enhance the change; and when there is no change in the signal, the first order differentiation will not respond.

Basic operator of first order edge detection (First Order Edge Detection)

Define the vertical edge: (E is the abbreviation of edge)

\mathbf{E} \mathbf{x}_{x,y}=\left|\mathbf{P}_{x,y}-\mathbf{P}_{x+1,y}\right|

Define horizontal edges:

\mathbf{E} \mathbf{y}_{x,y}=\left|\mathbf{P}_{x,y}-\mathbf{P}_{x,y+1}\right|

Then the vertical and horizontal edges: (add the vertical and horizontal edges)

                                                \mathbf{E}_{x,y}=\left|2 times \mathbf{P}_{x,y}-\mathbf{P}_{x+1,y}-\mathbf{P}_ {x,y+1}\right|

It is called first-order edge detection.

The template is:

pseudocode:

function edge = basic_difference(inage)

for x = 1:cols-2 
    for y = 1:rows-2
        edge(y,x)=abs(2*image(y,x)-image(y+1,x)-image(y+1,x))
    end
end

-------------------------------------------------------------------------------------------------------------------------------- 

Improved first-order edge detection

Taylor series analysis shows that differential processing of adjacent points can be used to estimate the first derivative of the point

                

 Therefore, the improved first-order difference template is:

 Mx is the vertical template, and My is the horizontal template.

 So the improved formula is

\mathbf{E}_{x,y}=\left|  \mathbf{P}_{x-1,y}- \mathbf{P}_{x+1,y} +\mathbf{P}_{x,y-1}-\mathbf{P}_{x , y+1}\right|

---------------------------------------------------------------------------------------------------------------------------------

Rorberts cross operator

It is one of the earliest edge detection operators. It implements edge detection and uses two templates to calculate the differential on the diagonal instead of along the coordinate axis. The two templates are:

 The edge point Ex, y is the larger value of the two values ​​obtained by convolving the two templates at the image point Px, y, and the formula is:

\boldsymbol{E}_{x, y}=\max \left\{\left|M^{+} * \boldsymbol{P}_{x, y}\right|,\left|M^{-} * \boldsymbol{P}_{x, y}\right|\right\} \quad \forall x, y \in 1, N-1

 Application of Roberts crossover operator:

--------------------------------------------------------------------------------------------------------------------------------

Prewitt edge detection operator 

The Prewitt operator template is: 

 Where Mx is the vertical template and My is the horizontal template.

For the vertical template, first (a) the middle shaded part in the figure is the pixel value we require. It is equal to the convolution of the 8 pixel values ​​​​around it, that is, the inner product of Mx and these nine pixel values, pixel P_00 * 1 + P_01 * 0 + P_02 * (-1) + P_10 * 1 + P_11 * 0 + P_12 * (-1) + P_20 * 1 + P_21 * 0 + P_22 * (-1). Get Mx(x,y). (I don't understand what this symbol means)

For the horizontal template, first (b) the middle shaded part in the figure is the pixel value we require. It is equal to the convolution of the 8 pixel values ​​​​around it, that is, the inner product of Mx and these nine pixel values, pixel P_00 * 1 + P_01 * 1 + P_02 * 1 + P_10 * 0 + P_11 * 0 + P_12 * 0 + P_20 * (-1) + P_21 * (-1) + P_22 * (-1). 

Then take the square and root of Mx(x,y) and My(x,y) to get the pixel value in the center of our shaded part. This is a vector method, (similar to finding the hypotenuse of a triangle) as shown in the following formula.

                ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        M(x, y)=\sqrt{\operatorname{Mx}(x, y)^{2}+\operatorname{My}(x, y)^{2}}

The edge strength M represents the length of the vector, and the edge direction θ represents the direction of the vector.

        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        \theta(x, y)=\arctan \left(\frac{\operatorname{My}(x, y)}{\operatorname{Mx}(x, y)}\right)

Matlab code

image=double(imread('lizardsmall.png'));
[rows, cols]=size(image)
edge = zeros(rows,cols)
kernelx = [1,0,-1;1,0,-1;1,0,-1]
kernely = [1,1,1;0,0,0;-1,-1,-1]
for x = 2:cols-1 
    for y = 2:rows-1
        tempx = sum(sum(image(y-1:y+1,x-1:x+1) * kernelx,1),2);
        tempy = sum(sum(image(y-1:y+1,x-1:x+1) * kernely,1),2);
        edge(y,x)=abs(sqrt(tempx*tempx+tempy*tempy));
    end
end
imshow(uint8(edge)),title('original');


 

Sobel detection operator:

The Prewitt operator template is:

 The calculation formula of each pixel of the Sobel operator is the same as that of Prewitt, that is, the previous coefficients have changed.

Reference book "Feature extraction and image processing" Mark S. Nixon and Alberto S. Aguado 

Chinese version, "Feature Extraction and Image Processing"

Guess you like

Origin blog.csdn.net/qq_39696563/article/details/122975205