# Imfilter, FFT-bsed convolution speed

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 ('Greens function')
subplot 133, imshow (filteredFFT, []); title ('Gravitational potential')
`

• whoops! I was thinking of base 10, let me delete my comments then... – Fat32 Sep 29 '17 at 21:22
• I don't know but I think you are asking for a lot more significant points. That sort of thing really chews up processing. Do you know the runtime versus the number of significant points? If not you might look at: scicomp.stackexchange.com/questions/10356/… which might have answers or hints. If not you could post there and likely get an answer. – rrogers Oct 3 '17 at 19:42