How to obtain a gaussian filter in python

后端 未结 8 1378
广开言路
广开言路 2021-01-31 03:57

I am using python to create a gaussian filter of size 5x5. I saw this post here where they talk about a similar thing but I didn\'t find the exact way to get equivalent python c

8条回答
  •  太阳男子
    2021-01-31 04:27

    Hey, I think this might help you

    import numpy as np
    import cv2
    
    def gaussian_kernel(dimension_x, dimension_y, sigma_x, sigma_y):
        x = cv2.getGaussianKernel(dimension_x, sigma_x)
        y = cv2.getGaussianKernel(dimension_y, sigma_y)
        kernel = x.dot(y.T)
        return kernel
    g_kernel = gaussian_kernel(5, 5, 1, 1)
    print(g_kernel)
    
    [[0.00296902 0.01330621 0.02193823 0.01330621 0.00296902]
     [0.01330621 0.0596343  0.09832033 0.0596343  0.01330621]
     [0.02193823 0.09832033 0.16210282 0.09832033 0.02193823]
     [0.01330621 0.0596343  0.09832033 0.0596343  0.01330621]
     [0.00296902 0.01330621 0.02193823 0.01330621 0.00296902]]
    

提交回复
热议问题