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.

## How does the Prewitt operator works?

The Prewitt operator detects image edges by convolution with two filter masks. One for horizontal and one for vertical direction. At this way we can extract:

- Horizontal edges
- Vertical edges
- Both directions

The coefficients of Prewitt masks are:

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

For example we can represent *Gx* as:

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).

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:

## 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.

## Other gradient operators

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

- Sobel-Feldman operator
- Scharr operator

## 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

- Simple Image class template in C++
- Prewitt operator in pure JavaScript
- Image edge detection with OpenGL / WebGL

## 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.

WEB APPLET

*See how it works in the browser!*

*You can support me at ko-fi.com*