✨我们将以下图为例,快速实践不同的形态学操作,如腐蚀 erode、膨胀 dilate、开 open、闭 close …
import cv2
import numpy as np
img = cv2.imread('D:\Desktop\csdn.png',0)
cv2.imshow('binary_Erode2', img)
cv2.waitKey(0)
💜 腐蚀 :内核在图像中滑动,当内核下存在(原始图像中的)像素不为
1 时,内核下的区域将被腐蚀 (变为零)
erosion = cv2.erode(img,kernel) ## 白色变小
import cv2
import numpy as np
img = cv2.imread('D:\Desktop\csdn.png',0)
kernel = np.ones((10,10),np.uint8)
erosion = cv2.erode(img,kernel) ###
cv2.imshow('binary_Erode', erosion)
cv2.waitKey(0)
💜 膨胀 :内核在图像中滑动,当内核下存在(原始图像中的)像素为
1 时,内核下的区域将被膨胀 (变为一)
dilation = cv2.dilate(img,kernel) ## 白色变大
import cv2
import numpy as np
img = cv2.imread('D:\Desktop\csdn.png',0)
kernel = np.ones((10,10),np.uint8)
dilation = cv2.dilate(img,kernel) ###
cv2.imshow('binary_Dilation', dilation)
cv2.waitKey(0)
💜 开运算 :腐蚀再膨胀
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
import cv2
import numpy as np
img = cv2.imread('D:\Desktop\csdn.png',0)
kernel = np.ones((10,10),np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) ###
cv2.imshow('binary_Opening ', opening)
cv2.waitKey(0)
💜 闭运算 :膨胀再腐蚀
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
import cv2
import numpy as np
img = cv2.imread('D:\Desktop\csdn.png',0)
kernel = np.ones((10,10),np.uint8)
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) ###
cv2.imshow('binary_Closing', closing)
cv2.waitKey(0)