源码:
import cv2 as cv
import numpy as np
# 高斯双边模糊
def bi_demo(image, sigmacolor, sigmaspace):
# Parameter:
# 1. src : Source 8-bit or floating-point, 1-channel or 3-channel image.
# 2. d : Diameter of each pixel neighborhood that is used during filtering.
# If it is non-positive, it is computed from sigmaSpace .
# 3. sigmaColor : Filter sigma in the color space. A larger value of the
# parameter means that farther colors within the pixel neighborhood (see
# sigmaSpace ) will be mixed together, resulting in larger areas of
# semi-equal color.
# 4. sigmaSpace : Filter sigma in the coordinate space. A larger value of
# the parameter means that farther pixels will influence each other as
# long as their colors are close enough (see sigmaColor ). When d>0 ,
# it specifies the neighborhood size regardless of sigmaSpace . Otherwise,
# d is proportional to sigmaSpace .
dst = cv.bilateralFilter(image, 0, sigmacolor, sigmaspace)
return dst
# 均值迁移
def shift_demo(image, sp, sr):
# Parameters:
# src: 操作图像。
# sp: 漂移物理空间半径大小。
# sr: 漂移色彩空间半径大小。
dst = cv.pyrMeanShiftFiltering(image, sp, sr)
return dst
print("-----------Hello Python------------")
src = cv.imread("C:/cvtest/woman1.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
# dst = bi_demo(src, 50, 15)
# cv.imshow("bi_demo1", dst)
# dst = bi_demo(src, 100, 15)
# cv.imshow("bi_demo2", dst)
dst = shift_demo(src, 10, 20)
cv.imshow("shift_demo1", dst)
dst = shift_demo(src, 10, 80)
cv.imshow("shift_demo2", dst)
cv.waitKey(0)
cv.destroyAllWindows()