Problem Statement: Write a matlab code for edge detection of a grayscale image without using in-built function of edge detection.
About 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.
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:
- Flip the mask horizontally and then vertically. This will result in 180-degree rotation of an image.
- Slide the mask onto the image such that every pixel in the image coincides with the center of the mask atleast once.
- Multiply the corresponding elements with the pixel values below it and then add them.
- Repeat this procedure until all pixel values of the image have been calculated for updation.
Now, we will take 3×3 mask for the same.
3×3 Mask for vertical edges : [1, 0, -1; 1, 0, -1; 1, 0, -1]
3×3 Mask for horizontal edges : [1, 0, -1; 1, 0, -1; 1, 0, -1]
3×3 Mask for principal diagonal edges : [1, 0, -1; 1, 0, -1; 1, 0, -1]
3×3 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.
Matlab code for horizontal edges:
Matlab code for principal diagonal edges:
Matlab Code for secondary diagonal edges:
Final Matlab code for edge detection:
- MATLAB - Image Edge Detection using Sobel Operator from Scratch
- MATLAB - Image Edge Detection using Robert Operator from Scratch
- MATLAB - Image Edge Detection using Prewitt Operator from Scratch
- Image Edge Detection Operators in Digital Image Processing
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Image Processing in Python (Scaling, Rotating, Shifting and Edge Detection)
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Matlab program to rotate an image 180 degrees clockwise without using function
- Wand image.edge function in Python
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- Python - Edge Detection using Pillow
- MATLAB | RGB image to grayscale image conversion
- MATLAB | RGB image representation
- Negative of an image in MATLAB
- Image Complement in Matlab
- Image Resizing in Matlab
- Matlab | Dilation of an Image
- Matlab | Erosion of an Image
- Create Mirror Image using MATLAB
- How to vertically flip an Image using MATLAB