Edge detection using first derivative operator in MATLAB
Last Updated :
16 Oct, 2021
An edge in an image is a significant local change in image intensity, usually associated with a discontinuity in image intensity or the first derivative of image intensity. The discontinuities in the intensity of the image can be stepped discontinuities, in which the intensity of the image changes from one value on one side of the discontinuity to a different value on the opposite side, or a line discontinuity. , in which the intensity The image changes in value abruptly but then returns to the original value for a short distance. However, step and line edges are rare in actual images. Due to the low-frequency components or smoothing introduced by most detection devices, there are rarely any sharp discontinuities in the actual signals. The edges of the steps become the edges of the ramps, and the edges of the lines become the edges of the roof, where changes in intensity are not instantaneous but occur over a finite distance.
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.
Now we detect edge using the first derivative operator with different coordinates. To detect an edge using the forward operator we use given below steps:
Steps:
- 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 X and Y axes.
- Display all the images.
Syntax:
var_name = imread(" name of image . extension ");
var_name = rgb2gray ( old_image_var);
var_name = double(image);
mask = [1 -1 0];
Kx = conv2(image_var, mask, 'same');
Ky = conv2(image_var, mask', 'same');
Final_image = sqrt ( Kx.^2 + Ky.^2);
imtool(image, []);
imtool(abs(image), []);
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.
Forward operator [1 -1 0]:
Example 1:
Matlab
% MATLAB code for Forward
% operator edge detection
k=imread("logo.png");
k=rgb2gray(k);
k1=double(k);
forward_msk=[1 -1 0];
kx=conv2(k1, forward_msk, 'same');
ky=conv2(k1, forward_msk', 'same');
ked=sqrt(kx.^2 + ky.^2);
%display the images.
imtool(k,[]);
%display the edge detection along x-axis.
imtool(kx,[]);
imtool(abs(kx), []);
%display the edge detection along y-axis.
imtool(ky,[]);
imtool(abs(ky),[]);
%display the full edge detection.
imtool(ked,[]);
imtool(abs(ked),[]);
Output:
gray image.
Edge detected imageCentral Operator [1 0 -1]:
Example 2:
Matlab
% MATLAB code for Central
% operator edge detection
k=imread("logo.png");
k=rgb2gray(k);
k1=double(k);
central_msk=[1/2 0 -1/2];
kx=conv2(k1, central_msk, 'same');
ky=conv2(k1, central_msk', 'same');
ked=sqrt(kx.^2 + ky.^2);
%display the images.
imtool(k,[]);
%display the edge detection along x-axis.
imtool(kx,[]);
imtool(abs(kx), []);
%display the edge detection along y-axis.
imtool(ky,[]);
imtool(abs(ky),[]); %binarised form
%display the full edge detection.
imtool(abs(ked),[]);
Output:
Here, we can observe that the edge is more clearly visible.
Gray image
Edge detected imageBackward Operator [0 1 -1]:
Example 3:
Matlab
% MATLAB code for Backward
% operator edge detection
k=imread("logo.png");
k=rgb2gray(k);
k1=double(k);
backward_msk=[0 1 -1];
kx=conv2(k1, backward_msk, 'same');
ky=conv2(k1, backward_msk', 'same');
ked=sqrt(kx.^2 + ky.^2);
%display the images.
imtool(k,[]);
%display the edge detection along x-axis.
imtool(kx,[]);
imtool(abs(kx), []);
%display the edge detection along y-axis.
imtool(ky,[]);
imtool(abs(ky),[]);
%display the full edge detection.
imtool(ked,[]);
imtool(abs(ked),[]);
Output:
Original image
Edge detected image
Similar Reads
MATLAB - Image Edge Detection using Sobel Operator from Scratch Sobel Operator: It is a discrete differentiation gradient-based operator. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Sobel operator produces either the normal to a vector or the corresponding gradient vector. It uses tw
3 min read
Edge detection using in-built function in MATLAB Edge detection: In an image, an edge is a curve that follows a path of rapid change in intensity of that image. Edges are often associated with the boundaries of the object in a scene environment. Edge detection is used to identify the edges in an image to make image processing easy. Edge detection
2 min read
Differential or Derivatives in MATLAB Differentiation of a function y = f(x) tells us how the value of y changes with respect to change in x. It can also be termed as the slope of a function. Derivative of a function f(x) wrt to x is represented as  {\displaystyle f'(x)= \frac {dy}{dx}} MATLAB allows users to calculate the derivative of
2 min read
Definite Numerical Integration Using Quad in MATLAB Pre-requisites: Definite Integration MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this function, we can compute definite integration. We use quad function which t
2 min read
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, u
4 min read
Boundary Extraction of image using MATLAB The boundary of the image is different from the edges in the image. Edges represent the abrupt change in pixel intensity values while the boundary of the image is the contour. As the name boundary suggests that something whose ownership changes, in the image when pixel ownership changes from one sur
3 min read
Alternatives To Eval Function in MATLAB The eval function is one of MATLAB's most powerful and flexible commands. Eval is an acronym for evaluating, which is exactly what it does: it evaluates MATLAB expressions. Any command that can be executed from the MATLAB prompt may be executed from a Mfile using eval. Use of Eval Function:The Eval
3 min read
How to Linear Filtering Without Using Imfilter Function in MATLAB? Edges can be sharpened, random noise can be reduced, and uneven illuminations can be corrected using a linear filtering technique. Correlating the image with the proper filter kernel completes the process. The imfilter function calculates the value of each output pixel using double-precision floatin
3 min read
Digital Image Processing Algorithms using MATLAB Like it is said, "One picture is worth more than ten thousand words "A digital image is composed of thousands and thousands of pixels. An image could also be defined as a two-dimensional function, f(x, y), where x and y are spatial (plane) coordinates and therefore the amplitude of f at any pair of
8 min read
User defined function in MATLAB Functions let you do a specific task. User defined functions are the functions created by the users according to their needs. This article explains how the user defined function in MATLAB is created. Syntax : function [a1,...,an] = func(x1,...,xm) func is the function name a1,...,an are outputs x1,.
2 min read