Prewitt Operator
   HOME

TheInfoList



OR:

The Prewitt operator is used in
image processing An image or picture is a visual representation. An image can be two-dimensional, such as a drawing, painting, or photograph, or three-dimensional, such as a carving or sculpture. Images may be displayed through other media, including a pr ...
, particularly within
edge detection Edge or EDGE may refer to: Technology Computing * Edge computing, a network load-balancing system * Edge device, an entry point to a computer network * Adobe Edge, a graphical development application * Microsoft Edge, a web browser developed b ...
algorithms. Technically, it is a discrete differentiation operator, computing an approximation of the
gradient In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p gives the direction and the rate of fastest increase. The g ...
of the image intensity function. At each point in the image, the result of the Prewitt operator is either the corresponding gradient vector or the
norm Norm, the Norm or NORM may refer to: In academic disciplines * Normativity, phenomenon of designating things as good or bad * Norm (geology), an estimate of the idealised mineral content of a rock * Norm (philosophy), a standard in normative e ...
of this vector. The Prewitt operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical directions and is therefore relatively inexpensive in terms of computations like Sobel and Kayyali operators. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image. The Prewitt operator was developed by Judith M. S. Prewitt.


Simplified description

In simple terms, the operator calculates the ''
gradient In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p gives the direction and the rate of fastest increase. The g ...
'' of the image intensity at each point, giving the direction of the largest possible increase from light to dark and the rate of change in that direction. The result therefore shows how "abruptly" or "smoothly" the image changes at that point, and therefore how likely it is that part of the image represents an ''edge'', as well as how that edge is likely to be oriented. In practice, the magnitude (likelihood of an edge) calculation is more reliable and easier to interpret than the direction calculation. Mathematically, the
gradient In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p gives the direction and the rate of fastest increase. The g ...
of a two-variable function (here the image intensity function) is at each image point a 2D
vector Vector most often refers to: * Euclidean vector, a quantity with a magnitude and a direction * Disease vector, an agent that carries and transmits an infectious pathogen into another living organism Vector may also refer to: Mathematics a ...
with the components given by the
derivative In mathematics, the derivative is a fundamental tool that quantifies the sensitivity to change of a function's output with respect to its input. The derivative of a function of a single variable at a chosen input value, when it exists, is t ...
s in the horizontal and vertical directions. At each image point, the gradient vector points in the direction of largest possible intensity increase, and the length of the gradient vector corresponds to the rate of change in that direction. This implies that the result of the Prewitt operator at an image point which is in a region of constant image intensity is a zero vector and at a point on an edge is a vector which points across the edge, from darker to brighter values.


Formulation

Mathematically, the operator uses two 3×3 kernels which are convolved with the original image to calculate approximations of the derivatives - one for horizontal changes, and one for vertical. If we define \mathbf as the source image, and \mathbf and \mathbf are two images which at each point contain the horizontal and vertical derivative approximations, the latter are computed as: : \mathbf = \begin +1 &+1 &+1 \\ 0 &0 &0 \\ -1 &-1 &-1 \end * \mathbf \quad \mbox \quad \mathbf = \begin +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end * \mathbf where * here denotes the 2-dimensional
convolution In mathematics (in particular, functional analysis), convolution is a operation (mathematics), mathematical operation on two function (mathematics), functions f and g that produces a third function f*g, as the integral of the product of the two ...
operation. Since the Prewitt kernels can be decomposed as the products of an averaging and a differentiation kernel, they compute the gradient with smoothing. Therefore, it is a
separable filter A separable filter in image processing can be written as product of two more simple filters. Typically a 2-dimensional convolution operation is separated into two 1-dimensional filters. This reduces the computational costs on an N\times M image wit ...
. For example, \mathbf can be written as : \begin +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end = \begin 1\\ 1\\ 1 \end \begin +1 & 0 & -1 \end The ''x''-coordinate is defined here as increasing in the "left"-direction, and the ''y''-coordinate is defined as increasing in the "up"-direction. At each point in the image, the resulting gradient approximations can be combined to give the gradient magnitude, using: :\mathbf = \sqrt Using this information, we can also calculate the gradient's direction: :\mathbf = \operatorname\left(\right) where, for example, Θ is 0 for a vertical edge which is darker on the right side.


Example


Code example

% MATLAB Code , Prewitt Operator from Scratch % Read Input Image input_image = imread(' ame of input image file ile format); % Displaying Input Image input_image = uint8(input_image); figure, imshow(input_image); title('Input Image'); % Convert the truecolor RGB image to the grayscale image input_image = rgb2gray(input_image); % Convert the image to double input_image = double(input_image); % Pre-allocate the filtered_image matrix with zeros filtered_image = zeros(size(input_image)); % Prewitt Operator Mask Mx = 1 0 1; -1 0 1; -1 0 1 My = 1 -1 -1; 0 0 0; 1 1 1 % Edge Detection Process % When i = 1 and j = 1, then filtered_image pixel % position will be filtered_image(2, 2) % The mask is of 3x3, so we need to traverse % to filtered_image(size(input_image, 1) - 2 %, size(input_image, 2) - 2) % Thus we are not considering the borders. for i = 1:size(input_image, 1) - 2 for j = 1:size(input_image, 2) - 2 % Gradient approximations Gx = sum(sum(Mx.*input_image(i:i+2, j:j+2))); Gy = sum(sum(My.*input_image(i:i+2, j:j+2))); % Calculate magnitude of vector filtered_image(i+1, j+1) = sqrt(Gx.^2 + Gy.^2); end end % Displaying Filtered Image filtered_image = uint8(filtered_image); figure, imshow(filtered_image); title('Filtered Image'); % Define a threshold value thresholdValue = 100; % varies between 255 output_image = max(filtered_image, thresholdValue); output_image(output_image

round(thresholdValue)) = 0; % Displaying Output Image output_image = im2bw(output_image); figure, imshow(output_image); title('Edge Detected Image');


See also

*
Sobel operator The Sobel operator, sometimes called the Sobel–Feldman operator or Sobel filter, is used in image processing and computer vision, particularly within edge detection algorithms where it creates an image emphasising edges. It is named after Ir ...
*
Laplace operator In mathematics, the Laplace operator or Laplacian is a differential operator given by the divergence of the gradient of a Scalar field, scalar function on Euclidean space. It is usually denoted by the symbols \nabla\cdot\nabla, \nabla^2 (where \ ...
*
Roberts Cross #REDIRECT Roberts cross {{redirect category shell, {{R from other capitalisation{{R from move ...
*
Edge detection Edge or EDGE may refer to: Technology Computing * Edge computing, a network load-balancing system * Edge device, an entry point to a computer network * Adobe Edge, a graphical development application * Microsoft Edge, a web browser developed b ...
*
Feature detection (computer vision) In computer vision and image processing, a feature is a piece of information about the content of an image; typically about whether a certain region of the image has certain properties. Features may be specific structures in the image such as ...
*
Digital image processing Digital image processing is the use of a digital computer to process digital images through an algorithm. As a subcategory or field of digital signal processing, digital image processing has many advantages over analog image processing. It allo ...
*
Computer vision Computer vision tasks include methods for image sensor, acquiring, Image processing, processing, Image analysis, analyzing, and understanding digital images, and extraction of high-dimensional data from the real world in order to produce numerical ...
*
Feature extraction Feature may refer to: Computing * Feature recognition, could be a hole, pocket, or notch * Feature (computer vision), could be an edge, corner or blob * Feature (machine learning), in statistics: individual measurable properties of the phenome ...
*
Image gradient An image gradient is a directional change in the intensity or color in an image. The gradient of the image is one of the fundamental building blocks in image processing. For example, the Canny edge detector uses image gradient for edge detection. ...
*
Image derivative Image derivatives can be computed by using small convolution filters of size 2 × 2 or 3 × 3, such as the Laplacian, Sobel, Roberts and Prewitt operators. However, a larger mask will generally give a better approximation of ...
*
Gabor filter In image processing, a Gabor filter, named after Dennis Gabor, who first proposed it as a 1D filter. The Gabor filter was first generalized to 2D by Gösta Granlund, by adding a reference direction. The Gabor filter is a linear filter used for ...


References

{{Reflist Geeks for geeks (28 Jul, 2023)
MATLAB – Image Edge Detection using Prewitt Operator from Scratch
Edge detection