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()

阀值变化结果

opencv for python 之 图像处理 阀值转换 侵蚀_第1张图片

扩展膨胀变化

侵蚀:翻转的的扩展

opencv for python 之 图像处理 阀值转换 侵蚀_第2张图片

你可能感兴趣的:(python,python)