![]() |
VOOZH | about |
Problem Statement:
Write a matlab code for edge detection of a grayscale image without using in-built function of edge detection.
Edge detection is an image processing technique for finding the boundaries of objects within images. It works by detecting discontinuities in brightness. Edge detection is used for image segmentation and data extraction in areas such as image processing, computer vision, and machine vision.
Approach:
For edge detection, we take the help of convolution: Convolution = I * m where
I
is the image, m is the mask and * is convolutional operator. To perform convolution on an image following steps are required:
Now, we will take 3x3 mask for the same. 3x3 Mask for vertical edges : [1, 0, -1; 1, 0, -1; 1, 0, -1] 3x3 Mask for horizontal edges : [1, 0, -1; 1, 0, -1; 1, 0, -1] 3x3 Mask for principal diagonal edges : [1, 0, -1; 1, 0, -1; 1, 0, -1] 3x3 Mask for secondary diagonal edges : [1, 0, -1; 1, 0, -1; 1, 0, -1]
We'll find these edges separately and finally combine them using
max
function or mean function, but
max
function is more accurate for this.
Original image:
👁 ImageMatlab Code for vertical edges:
Output:
👁 ImageMatlab code for horizontal edges:
Output:
👁 ImageMatlab code for principal diagonal edges:
Output:
👁 ImageMatlab Code for secondary diagonal edges:
Output:
👁 ImageFinal Matlab code for edge detection:
Output: