0
我在Matlab中創建了一個高斯濾波器。我創建了以下用於創建內核的代碼。與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
我不缺少算法中的任何步驟。我想弄清楚爲什麼我們的結果不匹配。
克恩* E * L,籽粒不... – dda