Now we’ll be discussing the two very common morphology operators namely Erosion and Dilation. Inorder to do this , we need the following two OpenCV functions :
The main uses of the above to operations are :
- Removing noise
- Isolation of individual elements and joining of disparate elements in an image
This is more or less similar to the real-life erosion(soil erosion) as in one color erodes the other. Basically what happens is that the kernel is scanned over the image and a pixel in the original image is considered as 1(or 0 ) only if all the pixels under the kernel are 1(or 0) else it is eroded to 0( or 1).
Here is an example where I’ve used a 3×3 kernel with full of 1’s:
This is just the opposite of Erosion. Here pixel is considered as 1(or 0) if atlest one of the pixels under the kernel is 1(or 0).
import cv2 import numpy as np img = cv2.imread(’j.png’,0) kernel = np.ones((4,4),np.uint8) dilation = cv2.dilate(img,kernel,iterations = 2)