Home » Blog » Image Processing » Prewitt Operator for Edge Detection

Prewitt Operator for Edge Detection

In the realm of image processing, the ability to detect edges is crucial for understanding and interpreting visual information. Among the pioneering techniques that have shaped this field is the Prewitt operator, a powerful algorithm developed by Judith M. S. Prewitt.

Renowned for its effectiveness in identifying gradients, the Prewitt operator not only laid the groundwork for modern edge detection methods but also continues to be a vital tool in various applications, from computer vision to medical imaging. In this article, we will explore the mechanics of the Prewitt operator, its historical significance, and its enduring relevance in today’s digital landscape.

Marker Effect – Interactive Preview

image-marker-effect-fiveko-after.webp flower-roses.webp

How does the Prewitt operator works?

The Prewitt operator is used to detect edges in images through convolution with two distinct filter masks: one for horizontal edges and another for vertical edges. This approach allows us to extract:

  • Horizontal edges
  • Vertical edges
  • Edges in both directions

For more information on the process of convolution in image processing, you can refer to this article on image convolution.

The coefficients of the Prewitt masks are as follows:

prewitt-gradient-operator-masks
Prewitt operator with 3×3 masks

Like other gradient detection operators, this one also has a separable property.

For example we can represent Gx as:

prewitt-operator-separable-gx
Prewitt example of separable convolution for Gx

We apply both masks to each pixel of the image. In this way we find the difference in the intensity levels of the neighboring pixels in both directions. The result of this operation determines the so-called first derivative of the signal (image).

Gradient magnitude calculation

Using the following equation we can calculate the orientation of the edge of each pixel. This parameter allows very fast thinning of the resulting contour lines by the non-maximum suppression algorithm:

Gradient orientation

Example

The image below is an example result of Prewitt edge detector. To reduce noise in the picture, it is enhanced with Gaussian blur prior the edge detection process.

prewitt-gradient-detection-example
Example result of Prewitt edge detector with Gaussian filter with sigma 2.0

Other gradient operators

Gradient detection is a common task in image analysis and there are alternative operators for this purpose. Some of which are:

What is the difference between Prewitt and Sobel?

Gradient differentiation operators such as Prewitt, Sobel, and Scharr operate on the same fundamental principle. They all utilize separable kernels to approximate the gradient of an image.

The key difference lies in how these filters assign weights to the pixels within their masks. The Prewitt filter applies equal weight to all pixels under the mask, while both Sobel and Scharr assign greater weight to pixels closer to the center of the mask, thereby emphasizing the central pixel’s contribution more significantly.

Source code

Here are some related articles that provide programming approaches to implementing edge detection techniques:

These resources offer practical examples and code snippets to help you understand and implement the concepts discussed.

Gradient Detection Online

On our online test page you can see and compare the most popular gradient detectors for free without any installation, registration or whatever.

Interactive Web App

See how it works in the browser!

Gradient detection demo app

Transform Your Images: Explore Our Must-Have Tools!