opencv for python 之 图像处理 阀值转换 侵蚀

import cv2.cv as cv
#load image
filename = "../Video/cat.jpg"
image = cv.LoadImage(filename)
win_name = "test"
cv.NamedWindow(win_name)
win2_name = "test2"
cv.NamedWindow(win2_name)

#set created image
size = cv.GetSize(image)#(100, 100)
depth = 8
channels = 1
grey = cv.CreateImage(size, depth, channels)#create one 100x100 single channels image
cv.CvtColor(image, grey, cv.CV_BGR2GRAY)

阀值变化

#Thresholdind operations
threshold = 100
colour = 255
#cv.Threshold(image, image, threshold, colour,  cv.CV_THRESH_BINARY)
cv.Threshold(grey, grey, threshold, colour,  cv.CV_THRESH_BINARY)
cv.ShowImage(win2_name, grey)

cv.Threshold(grey, grey, threshold, colour, cv.CV_THRESH_OTSU)
cv.ShowImage(win_name, grey)
'''

形态学变换
element_shape = cv.CV_SHAPE_RECT
pos = 1
element = cv.CreateStructuringElementEx(pos*2+1, pos*2+1, pos, pos, element_shape)

扩张变化
cv.Dilate(grey, grey, element, 2)

侵蚀变化
cv.Erode(grey, grey, element, 2)
cv.ShowImage(win_name, grey)
cv.ShowImage(win2_name, grey)
'''
cv.WaitKey()

阀值变化结果

扩展膨胀变化

侵蚀:翻转的的扩展

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值