本文整理汇总了Python中cv2.boxFilter方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.boxFilter方法的具体用法?Python cv2.boxFilter怎么用?Python cv2.boxFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.boxFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: niBlackThreshold
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def niBlackThreshold( src, blockSize, k, binarizationMethod= 0 ):
mean = cv2.boxFilter(src,cv2.CV_32F,(blockSize, blockSize),borderType=cv2.BORDER_REPLICATE)
sqmean = cv2.sqrBoxFilter(src, cv2.CV_32F, (blockSize, blockSize), borderType = cv2.BORDER_REPLICATE)
variance = sqmean - (mean*mean)
stddev = np.sqrt(variance)
thresh = mean + stddev * float(-k)
thresh = thresh.astype(src.dtype)
k = (src>thresh)*255
k = k.astype(np.uint8)
return k
# cv2.imshow()
示例2: _process
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def _process(
self,
im,
image_scale: Param(0.5, (0.05, 1.0)),
filter_size: Param(2, (0, 15)),
color_invert: Param(True),
clip: Param(140, (0, 255)),
**extraparams
):
""" Optionally resizes, smooths and inverts the image
:param im:
:param state:
:param filter_size:
:param image_scale:
:param color_invert:
:return:
"""
if image_scale != 1:
im = cv2.resize(
im, None, fx=image_scale, fy=image_scale, interpolation=cv2.INTER_AREA
)
if filter_size > 0:
im = cv2.boxFilter(im, -1, (filter_size, filter_size))
if color_invert:
im = 255 - im
if clip > 0:
im = np.maximum(im, clip) - clip
if self.set_diagnostic == "filtered":
self.diagnostic_image = im
return NodeOutput([], im)
示例3: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def main():
image = cv2.imread("../data/7.1.01.tiff", 1)
'''
# Kernal or Convolution matrix for Identity Filter
kernal = np.array(([0, 0, 0],
[0, 1, 0],
[0, 0, 0]), np.float32)
# Kernal or Convolution matrix for Edge Detection
kernal = np.array(([-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]), np.float32)
'''
# Kernal or Convolution matrix for Box BLue Filter
kernal = np.ones((5, 5), np.uint8) / 25
output = cv2.filter2D(image, -1, kernal)
# Low pass filters implementation
box_blur = cv2.boxFilter(image, -1, (31, 31))
simple_blur = cv2.blur(image, (21, 21))
gaussian_blur = cv2.GaussianBlur(image, (51, 51), 0)
cv2.imshow("Orignal Image", image)
cv2.imshow("Filtered Image", output)
cv2.imshow("Box Blur", box_blur)
cv2.imshow("Simple Blur", simple_blur)
cv2.imshow("Gaussian Blur", gaussian_blur)
cv2.waitKey(0)
cv2.destroyAllWindows()