How to obtain a gaussian filter in python

后端 未结 8 1455
广开言路
广开言路 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:33

    I found similar solution for this problem:

    def fspecial_gauss(size, sigma):
    
        """Function to mimic the 'fspecial' gaussian MATLAB function
        """
    
        x, y = numpy.mgrid[-size//2 + 1:size//2 + 1, -size//2 + 1:size//2 + 1]
        g = numpy.exp(-((x**2 + y**2)/(2.0*sigma**2)))
        return g/g.sum()
    

提交回复
热议问题