conv2fft_reuse

by

 

06 Mar 2011 (Updated )

Reuse intermediary results in multiple related convolutions with the same data but different kernels

filter2fft (h, X, shape, Xfft)
function [out, Xfft] = filter2fft (h, X, shape, Xfft)
    if (nargin < 3) || isempty(shape),  shape = 'same';  end
    %if (nargin < 3) || isempty(shape),  shape = 'full';  end  % WRONG!
    if (nargin < 4),  Xfft = [];  end
    h = rot90(h, 2);  % consistency with filter2.
    [out, Xfft] = conv2fft (h, X, shape, Xfft);
end

%!test
%! %rand('seed',0)  % DEBUG
%! sizes = ceil(10*rand(1,4));
%! h = rand(sizes(1:2));
%! %h = 1;  % DEBUG
%! X = rand(sizes(3:4));
%! for shape={'same','full','valid'},  shape = shape{1};
%!   outa = filter2 (h, X, shape);
%!   [outb, Xfft] = filter2fft (h, X, shape);
%!   outc = filter2fft (h, X, shape, Xfft);
%!   %outa, outb
%!   %outc - outb
%!   %outb - outa
%!   %max(abs(outb(:) - outa(:)))
%!   %max(abs(outc(:) - outb(:)))
%!   myassert(outb, outa, -100*eps())
%!   myassert(outc, outb)
%! end  % for

Contact us