Morphological operations are a set of operations that process images based on shapes. They apply a structuring element to an input image and generate an output image.
The most basic morphological operations are two: Erosion and Dilation
Basics of Erosion:
- Erodes away the boundaries of foreground object
- Used to diminish the features of an image.
Working of erosion:
- A kernel(a matrix of odd size(3,5,7) is convolved with the image.
- A pixel in the original image (either 1 or 0) will be considered 1 only if all the pixels under the kernel is 1, otherwise it is eroded (made to zero).
- Thus all the pixels near boundary will be discarded depending upon the size of kernel.
- So the thickness or size of the foreground object decreases or simply white region decreases in the image.
Basics of dilation:
- Increases the object area
- Used to accentuate features
Working of dilation:
- A kernel(a matrix of odd size(3,5,7) is convolved with the image
- A pixel element in the original image is ‘1’ if atleast one pixel under the kernel is ‘1’.
- It increases the white region in the image or size of foreground object increases
The second image is the eroded form of the original image and the third image is the dilated form.
Uses of Erosion and Dilation:
- It is useful for removing small white noises.
- Used to detach two connected objects etc.
- In cases like noise removal, erosion is followed by dilation. Because, erosion removes white noises, but it also shrinks our object. So we dilate it. Since noise is gone, they won’t come back, but our object area increases.
- It is also useful in joining broken parts of an object.
This article is contributed by Pratima Upadhyay. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Matlab | Dilation of an Image
- Matlab | Erosion of an Image
- Python | Create video using multiple images using OpenCV
- Addition and Blending of images using OpenCV in Python
- Python | Denoising of colored images using opencv
- Python | Grayscaling of Images using OpenCV
- Python - Process images of a video using OpenCV
- Drawing with Mouse on Images using Python-OpenCV
- Measure similarity between images using Python-OpenCV
- Concatenate images using OpenCV in Python
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Stitching input images (panorama) using OpenCV with C++
- Draw geometric shapes on images using OpenCV
- Java Program to Blur Images using OpenCV
- Python OpenCV - Depth map from Stereo Images
- Transition from OpenCV 2 to OpenCV 3.x
- Python | Copy and Paste Images onto other Image using Pillow
- How to compress images using Python and PIL?