How to obtain a gaussian filter in python

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

    Using Gaussian PDF and assuming space invariant blur

    def gaussian_kernel(sigma, size):
        mu = np.floor([size / 2, size / 2])
        size = int(size)
        kernel = np.zeros((size, size))
        for i in range(size):
            for j in range(size):
                kernel[i, j] = np.exp(-(0.5/(sigma*sigma)) * (np.square(i-mu[0]) + 
                np.square(j-mu[0]))) / np.sqrt(2*math.pi*sigma*sigma)```
    
        kernel = kernel/np.sum(kernel)
        return kernel
    

提交回复
热议问题