Sobel
|
In image processing, the Sobel operator is a simple edge detection algorithm using the 1st derivative of the intensity information.
The operator uses two 3x3 kernels convolved with the original image to produce a map of intensity gradient. The areas of highest gradient are where the intensity of the image changes rapidly over a few pixels, and are thus likely to represent edges.
Two convolution kernels are needed to detect the first-order derivative of both horizontal and vertical changes in a 2-dimensional image. If we define <math>\mathbf{A}<math> as the source image, we can compute:
<math> \mathbf{G_x} = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} * \mathbf{A} \ and\ \mathbf{G_y} = \begin{bmatrix} +1 & +2 & +1 \\ 0 & 0 & 0 \\ -1 & -2 & -1 \end{bmatrix} * \mathbf{A} <math>
Which can then be combined to give the overall magnitudes using:
- <math>\mathbf{G} = \sqrt{ \mathbf{G_x}^2 + \mathbf{G_y}^2 }<math>
Using this information, we can also calculate the gradient's direction:
- <math>\mathbf{\Theta} = \operatorname{arctan}\left({ \mathbf{G_y} \over \mathbf{G_x} }\right)<math>
Where <math>\Theta<math> will be 0 for a vertical edge, and will increase for edges anti-clockwise of this.