Edge detection using Prewitt, Scharr and Sobel Operator
The discontinuity in the image brightness is called an edge. Edge detection is the technique used to identify the regions in the image where the brightness of the image changes sharply. This sharp change in the intensity value is observed at the local minima or local maxima in the image histogram, using the first-order derivative.
The techniques used here in this article are first-order derivative techniques namely:
The Prewitt operator was developed by Judith M. S. Prewitt. Prewitt operator is used for edge detection in an image. Prewitt operator detects both types of edges, these are:
- Horizontal edges or along the x-axis,
- Vertical Edges or along the y-axis.
Wherever there is a sudden change in pixel intensities, an edge is detected by the mask. Since the edge is defined as the change in pixel intensities, it can be calculated by using differentiation. Prewitt mask is a first-order derivate mask. In the graph representation of Prewitt-mask’s result, the edge is represented by the local maxima or local minima.
Both the first and second derivative masks follow these three properties:
- More weight means more edge detection.
- The opposite sign should be present in the mask. (+ and -)
- The Sum of the mask values must be equal to zero.
Prewitt operator provides us two masks one for detecting edges in the horizontal direction and another for detecting edges in a vertical direction.
Prewitt Operator [X-axis] = [ -1 0 1; -1 0 1; -1 0 1]
Prewitt Operator [Y-axis] = [1 1 1; 1 1 1; 1 1 1]
- Read the image.
- Convert into grayscale if it is colored.
- Convert into the double format.
- Define the mask or filter.
- Detect the edges along X-axis.
- Detect the edges along Y-axis.
- Combine the edges detected along the X and Y axes.
- Display all the images.
Imtool() is the inbuilt function in Matlab. It is used to display the image. It takes 2 parameters; the first is the image variable and the second is the range of intensity values. We provide an empty list as the second argument which means the complete range of intensity has to be used while displaying the image.
This is a filtering method used to identify and highlight gradient edges/features using the first derivative. Performance is quite similar to the Sobel filter.
Scharr Operator [X-axis] = [-3 0 3; -10 0 10; -3 0 3];
Scharr Operator [Y-axis] = [ 3 10 3; 0 0 0; -3 -10 -3];
It is named after Irwin Sobel and Gary Feldman. Like the Prewitt operator Sobel operator is also used to detect two kinds of edges in an image:
- Vertical direction
- Horizontal direction
The difference between Sobel and Prewitt Operator is that in Sobel operator the coefficients of masks are adjustable according to our requirement provided they follow all properties of derivative masks.
Sobel-X Operator = [-1 0 1; -2 0 2; -1 0 1]
Sobel-Y Operator = [-1 -2 -1; 0 0 0; 1 2 1]