OpenCV学习(15)-高斯平滑

# -*- coding: utf-8 -*-
import sys
import cv2
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

def gaussBlur(img,sigma,h,w,_boundary='fill',_fillvalue=0):
    gaussKernel_x=cv2.getGaussianKernel(sigma,w,cv2.CV_64F)
    gausskernel_x=np.transpose(gaussKernel_x) #转置 
    gaussBlur_x=signal.convolve2d(img,gaussKernel_x,mode='same',boundary=_boundary,fillvalue=_fillvalue)
    gaussKernel_y=cv2.getGaussianKernel(sigma,h,cv2.CV_64F)
    gaussBlur_xy=signal.convolve2d(gaussBlur_x,gaussKernel_y,mode='same',boundary=_boundary,fillvalue=_fillvalue)
    blurimg=np.round(gaussBlur_xy)
    blurimg=blurimg.astype(np.uint8)
    return blurimg

if __name__=="__main__":
   if len(sys.argv)>1 :
      img = cv2.imread(sys.argv[1],0)
   else:
      print('None')
   cv2.imshow('img',img)
   blurimg=gaussBlur(img,25,100,100,'symm',0)#越平滑越模糊
   cv2.imshow('gaussblur',blurimg)
   cv2.waitKey(0)
   cv2.destroyAllWindows()

原图-高斯平滑处理后

OpenCV学习(15)-高斯平滑_第1张图片OpenCV学习(15)-高斯平滑_第2张图片

 

 

你可能感兴趣的:(opencv-图像平滑,python,opencv)