I want to convolve two large matrices and it is working fast - as long as one of those matrixes contains only separate points (point sources). If I replace the points by eg. Gaussians (line "HERE" below), it is getting terribly slow. My guess would be that Imfilter is swiching from FFT-based convolution to "normal" one.
Is there a way to avoid this? I need to use sizes up to 2^15.
% preapre image
len = 2^10; % size of both matrixes
mass = zeros (len);
mass = imnoise (mass, 'salt & pepper', 0.0001);
mass = mass.*(rand(len)).^2;
gauss = fspecial('gaussian', round(sqrt(len)), sqrt(sqrt(len)));
mass = imfilter (mass, gauss, 'replicate', 'conv'); % HERE
% prepare 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
filteredFFT = imfilter (g, mass, 'replicate', 'conv');
toc
% display results
figure('units', 'normalized', 'outerposition', [0 0.25 1 0.5])
subplot 131, imshow (mass, []); title ('Mass density')
subplot 132, imshow (g, []); title ('Green`s function')
subplot 133, imshow (filteredFFT, []); title ('Gravitational potential')