spm_field.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. function varargout = spm_field(varargin)
  2. % A compiled routine for various spatially regularised inverse problems.
  3. %_______________________________________________________________________
  4. %
  5. % FORMAT v = spm_field(H, g, param)
  6. % v - the solution (n1*n2*n3*n4, single)
  7. % H - parameterisation of a Hessian at each voxel
  8. % (n1*n2*n3*(n4*(n4-1)), single)
  9. % Because the Hessian is symmetric, elements along the
  10. % 4th dimension are ordered:
  11. % h(1,1), h(2,2), h(3,3),... h(1,2), h(1,3), ..., h(2,3)...
  12. % Each vector along the 4th dimension should encode a
  13. % positive (semi)definite matrix.
  14. % g - parameterisation of first derivatives (n1*n2*n3*n4, single)
  15. % param - 10 parameters (settings)
  16. % - [1][2][3] Voxel sizes
  17. % - [4][5][6] Regularisation settings.
  18. % - [4] Penalty on absolute values.
  19. % - [5] Penalty on the `membrane energy'. This penalises
  20. % the sum of squares of the gradients of the values.
  21. % - [6] Penalty on the `bending energy'. This penalises
  22. % the sum of squares of the 2nd derivatives.
  23. % - [7] Number of Full Multigrid cycles.
  24. % - [8] Number of relaxation iterations per cycle.
  25. %
  26. % The function solves equations using a Full Multigrid method (see
  27. % Press et al for more information), but incorporating the Hessian
  28. % of some form of likelihood term.
  29. % v = inv(A+B)*g
  30. % where A = param(4)*I + param(5)*L + param(6)*L'*L
  31. % and I = kron(kron(Iz,Iy),Ix)
  32. % L = kron(kron(Lz,Iy),Ix) + kron(kron(Iz,Ly),Ix) + kron(kron(Iz,Iy),Lx)
  33. %
  34. % Ix = eye(n1); Iy = eye(n2); Iz = eye(n3)
  35. % Lx = toeplitz([2 -1 0 ... 0 -1]/param(1)^2) etc
  36. %
  37. % Note that for ill-conditioned A, some regularisation of the solution
  38. % is included. This means that the solution is not identical to that
  39. % computed using other methods, it is still appropriate for use in
  40. % Gauss-Newton type optimisation schemes.
  41. % _______________________________________________________________________
  42. %
  43. % FORMAT u = spm_field('vel2mom', v, param)
  44. % v - A field (n1*n2*n3*n4, single).
  45. % param - 6 parameters (settings)
  46. % - [1][2][3] Voxel sizes
  47. % - [4][5][6] Regularisation parameters
  48. % u - Result of applying differential operator (n1*n2*n3*n4, single).
  49. %
  50. % This generates u = A*v, where A is computed as described above.
  51. % _______________________________________________________________________
  52. %
  53. % FORMAT b = spm_field('boundary')
  54. % Get the current boundary condition.
  55. % b - boundary condition
  56. % 0 - field wraps around at the boundary, as if the field is on a
  57. % torus (circulant). This is typically assumed when using
  58. % FFTs for convolution etc.
  59. % 1 - Neumann boundary condition.
  60. % Note that after a `clear functions' in MATLAB, the boundary
  61. % condition is reset to 0.
  62. % _______________________________________________________________________
  63. %
  64. % FORMAT spm_field('boundary',b)
  65. % Set the boundary condition.
  66. % b - boundary condition (0 or 1, see above).
  67. %_______________________________________________________________________
  68. % Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
  69. % John Ashburner
  70. % $Id: spm_field.m 5981 2014-05-13 12:47:14Z john $
  71. %-This is merely the help file for the compiled routine
  72. error('spm_field.c not compiled - see Makefile')