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:
- 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
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- MATLAB | RGB image to grayscale image conversion
- Matlab | Erosion of an Image
- Matlab | Dilation of an Image
- Image Complement in Matlab
- Image Resizing in Matlab
- MATLAB | RGB image representation
- Create Mirror Image using MATLAB
- How to vertically flip an Image using MATLAB
- Extract bit planes from an Image in Matlab
- LSB based Image steganography using MATLAB
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.