2024-09-01
Python
00

opencv中的模糊方法使用

python
import cv2 import numpy as np def Gaussian(image): # 进行高斯模糊 ksize = (11, 11) # 模糊核的大小 sigmaX = 5 # X方向的标准差,设为0表示从ksize计算 image = cv2.GaussianBlur(image, ksize, sigmaX) image = cv2.GaussianBlur(image, ksize, sigmaX) return image def blur(image): # 进行均值模糊 ksize = (11, 11) # 模糊核的大小 image = cv2.blur(image, ksize) image = cv2.blur(image, ksize) return image def medianBlur(image): # 进行中值模糊 ksize = 11 # 模糊核的大小 image = cv2.medianBlur(image, ksize) image = cv2.medianBlur(image, ksize) return image def bilateralFilter(image): # 进行双边滤波 d = 15 # 领域直径 sigmaColor = 75 # 色彩空间的标准差 sigmaSpace = 75 # 坐标空间的标准差 image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) return image def medianBlur(image): # 进行双边滤波 d = 15 # 领域直径 sigmaColor = 75 # 色彩空间的标准差 sigmaSpace = 75 # 坐标空间的标准差 image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) image = cv2.bilateralFilter(image, d, sigmaColor, sigmaSpace) return image def filter2D(image): # 自定义模糊核 kernel = np.ones((5, 5), dtype=np.float32) / 25 # 5x5的均匀权重的模糊核 # 进行自定义模糊 image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) image = cv2.filter2D(image, -1, kernel) return image # 读取图像 image = cv2.imread('image.jpg') image = filter2D(image) # 显示模糊后的图像 cv2.imshow('Gaussian Blur', image) cv2.waitKey(0) cv2.destroyAllWindows()
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!