opencv use cv2.erode () and cv2.dilate () and the expanded image CORROSION

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
Here Insert Picture Description

  1. 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()

Here Insert Picture Description
Here Insert Picture Description

  1. 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()

Here Insert Picture Description
Reference Links: https://www.cnblogs.com/yqs-0705/p/10150026.html

Published 27 original articles · won praise 20 · views 1553

Guess you like

Origin blog.csdn.net/qq_39507748/article/details/104539073