fast_conv_fft.m 758 B

12345678910111213141516171819202122232425
  1. function Y = fast_conv_fft( X, fH, pad_value )
  2. % Convolve with a large support kernel in the Fourier domain.
  3. %
  4. % Y = fast_conv_fft( X, fH, pad_value )
  5. %
  6. % X - image to be convolved (in spatial domain)
  7. % fH - filter to convolve with in the Fourier domain, idealy 2x size of X
  8. % pad_value - value to use for padding when expanding X to the size of fH
  9. %
  10. % (C) Rafal Mantiuk <mantiuk@gmail.com>
  11. % This is an experimental code for internal use. Do not redistribute.
  12. pad_size = (size(fH)-size(X));
  13. %mX = mean( X(:) );
  14. fX = fft2( padarray( X, pad_size, pad_value, 'post' ) );
  15. Yl = real(ifft2( fX.*fH, size(fX,1), size(fX,2), 'symmetric' ));
  16. %Yl = real(ifft2( fX.*fH));
  17. %Yl = real(ifft2( fX.*fH, size(fX,1), size(fX,2) ));
  18. Y = Yl(1:size(X,1),1:size(X,2));
  19. end