【问题标题】:How to implement Gaussian filter of kernel size 3如何实现内核大小为 3 的高斯滤波器
【发布时间】:2020-02-10 10:51:36
【问题描述】:

有人可以帮我计算高斯滤波器值吗?我看过其他相关帖子,但无法找出正确的解决方案。 我有二维高斯方程:

def gauss2d(x,y,sigma):
    return (1/(2*math.pi*math.pow(sigma,2)))*math.exp(-0.5*
                           (pow(x,2)+pow(y,2))/pow(sigma,2))  

我想弄清楚如何计算具有离散值的 3x3 或 5x5 高斯滤波器的元素

【问题讨论】:

标签: python image-processing gaussian gaussianblur


【解决方案1】:

这个实现在应用规范化时略有不同,但这只是一件小事。

def gaussian(sigma,Y,X):
    kernel = np.zeros((Y,X))
    ax = range(X) - np.floor(X/2)
    ay = range(Y) - np.floor(Y/2)
    xx,yy = np.meshgrid(ax,ay)
    kernel = np.exp(-0.5 * (np.square(xx) + np.square(yy)))/np.square(sigma)
    kernel = kernel/np.sum(kernel)
    return kernel 

print(np.sum(gaussian(0.3,5,5)))

【讨论】:

  • 我想知道内核过滤器的实现,比如 3x3 即 1/16[[1,2,1],[2,4,2],[1,2,1] ]
  • 实施是什么意思?上述代码就是实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-19
  • 2012-12-13
  • 2018-01-26
  • 2017-05-09
  • 2016-05-22
相关资源
最近更新 更多