spm_conv_full.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function [X] = spm_conv_full(X,sx,sy)
  2. % Hanning convolution (return full arrays)
  3. % FORMAT [X] = spm_conv_full(X,sx,sy)
  4. % X - matrix
  5. % sx - kernel width (FWHM) in pixels
  6. % sy - optional non-isomorphic smoothing
  7. %__________________________________________________________________________
  8. %
  9. % spm_conv_full is a one or two dimensional convolution of a matrix
  10. % variable in working memory. It capitalizes on the separablity of
  11. % multidimensional convolution with a hanning kernel by using
  12. % one-dimensional convolutions.
  13. %__________________________________________________________________________
  14. % Copyright (C) 1999-2013 Wellcome Trust Centre for Neuroimaging
  15. % Karl Friston
  16. % $Id: spm_conv_full.m 7749 2019-12-05 17:05:46Z guillaume $
  17. % assume isomorphic smoothing
  18. %--------------------------------------------------------------------------
  19. if nargin < 3; sy = sx; end
  20. sx = abs(sx);
  21. sy = abs(sy);
  22. [lx,ly] = size(X);
  23. % kernels : FWHM -> n
  24. %--------------------------------------------------------------------------
  25. Ex = min([fix(sx) lx]);
  26. kx = spm_hanning(2*Ex + 1);
  27. kx = kx/sum(kx);
  28. Ey = min([fix(sy) ly]);
  29. ky = spm_hanning(2*Ey + 1);
  30. ky = ky/sum(ky);
  31. % convolve
  32. %--------------------------------------------------------------------------
  33. if lx > 1
  34. for i = 1:ly
  35. u = X(:,i);
  36. v = [flipud(u(1:Ex)); u; flipud(u((1:Ex) + lx - Ex))];
  37. X(:,i) = conv(full(v),kx,'valid');
  38. end
  39. end
  40. if ly > 1
  41. for i = 1:lx
  42. u = X(i,:);
  43. v = [fliplr(u(1:Ey)) u fliplr(u((1:Ey) + ly - Ey))];
  44. X(i,:) = conv(full(v),ky,'valid');
  45. end
  46. end