自学内容网 自学内容网

【快速实践 OpenCV morphology】形态学操作:腐蚀、膨胀、开运算、闭运算

✨我们将以下图为例,快速实践不同的形态学操作,如腐蚀 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)

原文地址:https://blog.csdn.net/CODE_RabbitV/article/details/140664904

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!