6.opencv-python;cv2库;形态学;图像膨胀

import cv2 #opencv读取的格式是BGR
import numpy as np
import matplotlib.pyplot as plt#Matplotlib是RGB
%matplotlib inline 
 
# 读取
img=cv2.imread('lena.jpg')
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
 
# 图像二值化
ret, thresh1 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)

# 图像膨胀操作,3x3卷积核,值置1,调试循环次数,次数为100时,完全膨胀,全白
kernel = np.ones((3,3),np.uint8) 
dilate_0 = cv2.dilate(thresh1,kernel,iterations = 0)
dilate_1 = cv2.dilate(thresh1,kernel,iterations = 1)
dilate_2 = cv2.dilate(thresh1,kernel,iterations = 2)
dilate_3 = cv2.dilate(thresh1,kernel,iterations = 3)
dilate_4 = cv2.dilate(thresh1,kernel,iterations = 4)
dilate_5 = cv2.dilate(thresh1,kernel,iterations = 100)
res = np.hstack((dilate_0,dilate_1,dilate_2,dilate_3,dilate_4,dilate_5))
cv2.imshow('res', res)
cv2.waitKey(0)
cv2.destroyAllWindows()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值