Corrosion of the expansion part of morphological operations, a so-called morphological, is to change the shape of the object, image understanding of some: Corrosion = thinner expansion fat =
Mainly used cv2.erode () and cv2.dilate () , point to note is that for erosion and dilation binarized image major white portion
- Corrosion: takes a minimum value in each small area in the original image, because it is the purpose of the binarized image, as long as there is a point 0, is 0, to achieve downsizing. Therefore, in the example below, we can use the pictures to corrosion in some of the glitches or very small thing to get rid of
img = cv2.imread('dige.png')
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
kernel = np.ones((3,3),np.uint8)
#iteration的值越高,模糊程度(腐蚀程度)就越高 呈正相关关系且只能是整数
erosion = cv2.erode(img,kernel,iterations = 1)
cv2.imshow('erosion', erosion)
cv2.waitKey(0)
cv2.destroyAllWindows()
- Expansion: a local maximum is achieved, the effect is "fat", we can directly manipulate corrosion example of the etched image erosion. In order to effect a little obvious, our iterations parameter values larger, is set to 3
kernel = np.ones((3,3),np.uint8)
dilate = cv2.dilate(erosion,kernel,iterations = 3)
cv2.imshow('dilate', dilate)
cv2.waitKey(0)
cv2.destroyAllWindows()
Reference Links: https://www.cnblogs.com/yqs-0705/p/10150026.html