Image Edge detection--sobel operator

Source: Internet
Author: User
Tags api manual

Edge is the most basic feature of image, which plays an important role in computer vision, image analysis and other applications, because the edge of image contains useful information for recognition, and is the main feature extraction method of image analysis and pattern recognition. 1. What is "image edge"? in the image, "edge" refers to the meaning of the threshold. The "critical" of an image is expressed as a place where the brightness of the image changes significantly, and the edge refers to the end of one area and the beginning of another region. "Edge point" refers to a point in an image where the coordinates [x, y] are in a position where the intensity changes significantly. 2. How do I indicate edge detection? in mathematics, the speed of change is expressed by derivative. Based on this, there are many methods for edge detection, the vast majority of them can be divided into two categories: a search-based and 0-crossing-based category. The search-based approach detects the boundary by looking for the maximum and minimum values in the first derivative of the image, usually locating the boundary in the direction of the highest gradient (think of the meaning of the first derivative as the speed of the change of the image, the greatest natural change is the most significant). Based on the 0 traversal method, we find the boundary by looking for the second derivative of the image 0, which is usually over 0 points of Laplacian over 0 points or nonlinear differential representations. The image can be regarded as a two-dimensional discrete function mathematically, and the image gradient is the derivation of this two-dimensional discrete function. The gradient of function f (x, Y) at (x, y) is a vector:

The size of this vector is calculated as: usually in order to improve efficiency, the usual approximate expression is:
The direction angle of the gradient is:

The difference is usually the equivalent of the differential in a discrete function, so the gradient of the computed image is often used in differential.   3.Sobel operatorThe cable bell operator (Sobeloperator) is one of the operators in image processing, which is mainly used for edge detection. Technically, it is a discrete difference operator that is used to calculate the approximate value of the gradient of the image luminance function. Using this operator at any point in the image will result in a corresponding gradient vector or its normal vector. FormulaThe operator consists of two sets of 3x3 matrices, transverse and longitudinal respectively, and the image as a plane convolution, can be obtained by the transverse and longitudinal luminance difference approximation. If the original image is represented by a, the GX and Gy represent images that are detected by transverse and longitudinal edges respectively, and the formula is as follows:
The calculation is as follows:

Gx = ( -1) *f (x-1, y-1) + 0*f (x,y-1) + 1*f (x+1,y-1)

+ ( -2) *f (x-1,y) + 0*f (x, y) +2*f (x+1,y)

+ ( -1) *f (x-1,y+1) + 0*f (x,y+1) + 1*f (x+1,y+1)

= [F (x+1,y-1) +2*f (x+1,y) +f (x+1,y+1)]-[f (x-1,y-1) +2*f (x-1,y) +f (x-1,y+1)]

Gy =1* F (x-1, y-1) + 2*f (x,y-1) + 1*f (x+1,y-1)

+0*f (x-1,y) 0*f (x, y) + 0*f (x+1,y)

+ ( -1) *f (x-1,y+1) + ( -2) *f (x,y+1) + ( -1) *f (x+1, y+1)

= [F (x-1,y-1) + 2f (x,y-1) + f (x+1,y-1)]-[f (x-1, y+1) + 2*f (x,y+1) +f (x+1,y+1)]

where F (A, B) represents the grayscale value of the image (A, b) point.

and then the GX and the Gy find out the F, if the F is greater than a certain threshold, the point (x, Y) is considered to be an edge point.

4. Practical effects

I use the Cvsobel () function in the OpenCV library in vs2013 to detect the edges of the input images. The effect is as follows:

Original:

Because the Sobel operator is suitable for grayscale images, it is also necessary to grayscale the original image:



The Gx, GY can detect the presence of edges, as well as the changes from dark to light, from light to dark. Calculation Only | Gx|, the strongest response is orthogonal to the edge of the x-axis, that is, to get the vertical edge; calculation Only | Gy|, the strongest response is orthogonal to the edge of the y-axis, which results in a horizontal edge.

Only for horizontal derivation (Gx):


You can see that you get a lot of vertical edges.

Derivation only in vertical direction (Gy):


Can be seen to get a lot of horizontal edges.

using GX and Gy to find out the F, which is the gradient vector, to its size | the F | The drawing is as follows:


Of course, because edge detection is sensitive to image noise, it is best to smooth the original images with Gaussian filter and then grayscale. I did not do this step here.

Because it is Sina blog, the relevant code can not be affixed, but also are some simple call, check OPENCV API manual know how to use.

Image Edge detection--sobel operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.