Prewitt operator for edge detection

The Prewitt operator is one of the first algorithms for edge detection by gradient transform. It is developed by Judith M. S. Prewitt and is a popular tool for image analysis.


Gradient Detection Demo

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


How does the Prewitt operator works?

The Prewitt operator works by a convolution with two filter masks that define the first derivative of the signal (image).

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

Like other gradient detection operators, this one has separable property as well. 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.

Gradient magnitude calculation

To calculate gradient orientation we can use the following equation:

Gradient orientation

Example

The image below is an example result of Prewitt edge detector. The picture is filtered with Gaussian blur to reduce image noise.

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?

In fact, the gradient differentiation operators like Prewitt, Sobel and Scharr share the same principle of work. All of them use a separable kernels to calculate the gradient approximation.

The main difference is that the Prewitt filter uses the same weight for all the pixels that fall under the masks. Unlike Prewitt, Sobel and Scharr give less weight to points far from the center pixel.

Source code


computer-vision-studio-thumb
Visit our free online Computer Vision Studio

Related articles