【问题标题】:Gaussian filter kernel different from Matlab Gaussian filter kernel高斯滤波器内核不同于 Matlab 高斯滤波器内核
【发布时间】:2017-02-04 06:07:04
【问题描述】:

我正在 Matlab 中创建一个高斯滤波器。我创建了以下代码来创建内核。

function kernel = gaussian_filter(sigma)
    kernel_width = 3 * sigma - 1;
    [x, y] = meshgrid(-kernel_width/2:kernel_width/2, -kernel_width/2:kernel_width/2);
    normalized_constant = 1/(2 * pi * sigma * sigma);
    kernel = normalized_constant * exp(-(x.^2 + y.^2)/ (2 * sigma * sigma));
    K = mat2gray(kernel);
    imshow(K);
    title('Gaussian Kernel');
 end

我的输出是:

gaussian_filter(3)

ans =

  Columns 1 through 7

    0.0030    0.0044    0.0058    0.0069    0.0073    0.0069    0.0058
    0.0044    0.0065    0.0086    0.0101    0.0107    0.0101    0.0086
    0.0058    0.0086    0.0113    0.0134    0.0142    0.0134    0.0113
    0.0069    0.0101    0.0134    0.0158    0.0167    0.0158    0.0134
    0.0073    0.0107    0.0142    0.0167    0.0177    0.0167    0.0142
    0.0069    0.0101    0.0134    0.0158    0.0167    0.0158    0.0134
    0.0058    0.0086    0.0113    0.0134    0.0142    0.0134    0.0113
    0.0044    0.0065    0.0086    0.0101    0.0107    0.0101    0.0086
    0.0030    0.0044    0.0058    0.0069    0.0073    0.0069    0.0058

  Columns 8 through 9

    0.0044    0.0030
    0.0065    0.0044
    0.0086    0.0058
    0.0101    0.0069
    0.0107    0.0073
    0.0101    0.0069
    0.0086    0.0058
    0.0065    0.0044
    0.0044    0.0030

但是当我运行 Matlab 高斯滤波器时,结果与我的输出略有偏差。

h = fspecial('gaussian', 9, 3)

h =

  Columns 1 through 7

    0.0040    0.0059    0.0077    0.0091    0.0096    0.0091    0.0077
    0.0059    0.0086    0.0114    0.0135    0.0142    0.0135    0.0114
    0.0077    0.0114    0.0150    0.0178    0.0188    0.0178    0.0150
    0.0091    0.0135    0.0178    0.0210    0.0222    0.0210    0.0178
    0.0096    0.0142    0.0188    0.0222    0.0235    0.0222    0.0188
    0.0091    0.0135    0.0178    0.0210    0.0222    0.0210    0.0178
    0.0077    0.0114    0.0150    0.0178    0.0188    0.0178    0.0150
    0.0059    0.0086    0.0114    0.0135    0.0142    0.0135    0.0114
    0.0040    0.0059    0.0077    0.0091    0.0096    0.0091    0.0077

  Columns 8 through 9

    0.0059    0.0040
    0.0086    0.0059
    0.0114    0.0077
    0.0135    0.0091
    0.0142    0.0096
    0.0135    0.0091
    0.0114    0.0077
    0.0086    0.0059
    0.0059    0.0040

我没有遗漏算法中的任何步骤。我想弄清楚为什么我们的结果不匹配。

【问题讨论】:

  • 内核el,不是内核...

标签: matlab filter computer-vision gaussian


【解决方案1】:

我忘记标准化内核:

kernel = kernel/(sum(kernel(:)));

https://www.mathworks.com/help/images/ref/fspecial.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 2013-03-29
    • 2011-02-15
    • 2023-04-09
    • 2017-12-12
    • 2012-12-13
    • 1970-01-01
    相关资源
    最近更新 更多