码迷,mamicode.com
首页 > 其他好文 > 详细

day 10 形态学处理 膨胀

时间:2017-11-27 23:40:30      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:key   des   read   关闭   有一个   pre   com   http   windows   

#-*- coding:utf-8 -*-

#1.导入包
import cv2
import numpy as np

#2.导入图片
img = cv2.imread(home.jpg,0)

#3.设置卷积核 5x5矩形卷积核
kernel = np.ones((5,5),np.uint8)
print(kernel)

kernel2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
print(kernel2)


#4.膨胀操作
dilation = cv2.dilate(img,kernel,iterations=1)
                      #第1参数:原图片
                      #第2参数:卷积核
                      #第3参数:只要5x5卷积核内中心像素有一个1,那就是1

#5.显示图片,并关闭
cv2.imshow(dilation,dilation)

cv2.waitKey(0)
cv2.destroyAllWindows()

    

[[1 1 1 1 1]
 [1 1 1 1 1]
 [1 1 1 1 1]
 [1 1 1 1 1]
 [1 1 1 1 1]]

[[0 0 1 0 0]
 [1 1 1 1 1]
 [1 1 1 1 1]
 [1 1 1 1 1]
 [0 0 1 0 0]]

 

  技术分享图片

 

day 10 形态学处理 膨胀

标签:key   des   read   关闭   有一个   pre   com   http   windows   

原文地址:http://www.cnblogs.com/venicid/p/7906145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!