Free Online Image Tools

Edit photos directly in your web browser!

Free Online Image Apps at Fiveko

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.


Edge Detection Tools

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:

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


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.

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 pixels that fall under the masks. Unlike Prewitt, Sobel and Scharr give less weight to points far from the center.

Source code

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.


See how it works in the browser!

Gradient detection demo app

Spectrum Audio Editor (Free!)

Effortless audio editing, made free. Edit sound like a pro with our online spectrum analyzer.

SoundCMD - Free Spectrum Audio Editor