Prewitt operator

From HandWiki

The Prewitt operator is used in image processing, particularly within edge detection algorithms. Technically, it is a discrete differentiation operator, computing an approximation of the gradient of the image intensity function. At each point in the image, the result of the Prewitt operator is either the corresponding gradient vector or the norm of this vector. The Prewitt operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical directions and is therefore relatively inexpensive in terms of computations like Sobel and Kayyali[1] operators. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image. The Prewitt operator was developed by Judith M. S. Prewitt.[2]

Simplified description

In simple terms, the operator calculates the gradient of the image intensity at each point, giving the direction of the largest possible increase from light to dark and the rate of change in that direction. The result therefore shows how "abruptly" or "smoothly" the image changes at that point, and therefore how likely it is that part of the image represents an edge, as well as how that edge is likely to be oriented. In practice, the magnitude (likelihood of an edge) calculation is more reliable and easier to interpret than the direction calculation.

Mathematically, the gradient of a two-variable function (here the image intensity function) is at each image point a 2D vector with the components given by the derivatives in the horizontal and vertical directions. At each image point, the gradient vector points in the direction of largest possible intensity increase, and the length of the gradient vector corresponds to the rate of change in that direction. This implies that the result of the Prewitt operator at an image point which is in a region of constant image intensity is a zero vector and at a point on an edge is a vector which points across the edge, from darker to brighter values.

Formulation

Mathematically, the operator uses two 3×3 kernels which are convolved with the original image to calculate approximations of the derivatives - one for horizontal changes, and one for vertical. If we define [math]\displaystyle{ \mathbf{A} }[/math] as the source image, and [math]\displaystyle{ \mathbf{G_x} }[/math] and [math]\displaystyle{ \mathbf{G_y} }[/math] are two images which at each point contain the horizontal and vertical derivative approximations, the latter are computed as:

[math]\displaystyle{ \mathbf{G_x} = \begin{bmatrix} +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end{bmatrix} * \mathbf{A} \quad \mbox{and} \quad \mathbf{G_y} = \begin{bmatrix} +1 & +1 & +1 \\ 0 & 0 & 0 \\ -1 & -1 & -1 \end{bmatrix} * \mathbf{A} }[/math]

where [math]\displaystyle{ * }[/math] here denotes the 2-dimensional convolution operation.

Since the Prewitt kernels can be decomposed as the products of an averaging and a differentiation kernel, they compute the gradient with smoothing. Therefore, it is a separable filter. For example, [math]\displaystyle{ \mathbf{G_x} }[/math] can be written as

[math]\displaystyle{ \begin{bmatrix} +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end{bmatrix} = \begin{bmatrix} 1\\ 1\\ 1 \end{bmatrix} \begin{bmatrix} +1 & 0 & -1 \end{bmatrix} }[/math]

The x-coordinate is defined here as increasing in the "left"-direction, and the y-coordinate is defined as increasing in the "up"-direction. At each point in the image, the resulting gradient approximations can be combined to give the gradient magnitude, using:

[math]\displaystyle{ \mathbf{G} = \sqrt{ {\mathbf{G}_x}^2 + {\mathbf{G}_y}^2 } }[/math]

Using this information, we can also calculate the gradient's direction:

[math]\displaystyle{ \mathbf{\Theta} = \operatorname{atan2}\left({ \mathbf{G}_y , \mathbf{G}_x }\right) }[/math]

where, for example, Θ is 0 for a vertical edge which is darker on the right side.

Example

Grayscale image of a brick wall & a bike rack
Gradient with Prewitt operator of grayscale image of a brick wall & a bike rack

See also

References

  1. Dim, Jules R.; Takamura, Tamio (2013-12-11). "Alternative Approach for Satellite Cloud Classification: Edge Gradient Application" (in en). Advances in Meteorology 2013: 1–8. doi:10.1155/2013/584816. ISSN 1687-9309. 
  2. Prewitt, J.M.S. (1970). "Object Enhancement and Extraction". Academic Press.