我正在尝试在大型矩阵的 Matlab 中进行 2D 快速卷积。如果我使用基于卷积定理 ( https://en.wikipedia.org/wiki/Convolution_theorem ) 的 FFT 版本,图像中有一些伪影。只有 imfilter 产生正确的结果,但它的工作速度比 FFT 版本 (conv2fft) 慢约 100 倍。
可以做些什么来避免这些伪影?我知道在 1D 中我们需要补零,但这里的图像和内核都具有相同的大小。
% generate image
len = 2^10;
CICcut = zeros (len);
CICcut = imnoise (CICcut, 'salt & pepper', 0.0001);
CICcut = CICcut.*(rand(len)).^2;
gauss = fspecial('gaussian', round(sqrt(len)), sqrt(sqrt(len)));
CICcut = imfilter (CICcut, gauss, 'replicate', 'conv');
% generate kernel
g = zeros(len);
lenMone = len-1;
for i = 1:len
for j = 1:len
g(i, j) = ((i-1)/lenMone - 0.5)^2 + ((j-1)/lenMone - 0.5)^2;
end
end
g = -log(sqrt(g));
% convolution
tic
filtered = imfilter (g, CICcut, 'replicate', 'conv');
toc
tic
filteredFFT = conv2fft (g, CICcut, 'same');
toc
tic
filteredN = convn (g, CICcut, 'same');
toc
% display
figure('units', 'normalized', 'outerposition', [0 0.25 1 0.5])
subplot 151, imshow (CICcut, []); title ('Mass density')
subplot 152, imshow (g, []); title ('Green`s function')
subplot 153, imshow (filtered, []); title ({'Gravitational potential' 'imfilter'})
subplot 154, imshow (filteredFFT, []); title ({'Gravitational potential' 'conv2fft'})
subplot 155, imshow (filteredN, []); title ({'Gravitational potential' 'convn'})
最好的问候,亚历克斯