spm_mip.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. function mip = spm_mip(Z,XYZ,M,units)
  2. % SPM Maximum Intensity Projection
  3. % FORMAT mip = spm_mip(Z,XYZ,M,units)
  4. % Z - vector point list of SPM values for MIP
  5. % XYZ - matrix of coordinates of points (mip coordinates)
  6. % M - voxels - > mip matrix or size of voxels (mm)
  7. % units - defining space [default {'mm' 'mm' 'mm'}]
  8. %
  9. % mip - maximum intensity projection
  10. % if no output, the mip is displayed in current figure.
  11. %__________________________________________________________________________
  12. %
  13. % If the data are 2 dimensional [DIM(3) = 1] the projection is simply an
  14. % image, otherwise:
  15. %
  16. % spm_mip creates and displays a maximum intensity projection of a point
  17. % list of voxel values (Z) and their location (XYZ) in three orthogonal
  18. % views of the brain. It is assumed voxel locations conform to the space
  19. % defined in the atlas of Talairach and Tournoux (1988); unless the third
  20. % dimension is time.
  21. %
  22. % This routine loads a mip outline from MIP.mat. This is an image with
  23. % contours and grids defining the space of Talairach & Tournoux (1988).
  24. % mip95 corresponds to the Talairach atlas, mip96 to the MNI templates.
  25. % The outline and grid are superimposed at intensity 0.4.
  26. %
  27. % A customised mip outline can be used instead of the default.
  28. %
  29. % A default colormap of 64 levels is assumed. The pointlist image is
  30. % scaled to fit in the interval [1/9,1]*64 for display. Flat images
  31. % are scaled to 1*64.
  32. %
  33. % If M is not specified, it is assumed the XYZ locations are
  34. % in Talairach mm.
  35. %__________________________________________________________________________
  36. % Copyright (C) 1996-2013 Wellcome Trust Centre for Neuroimaging
  37. % Karl Friston
  38. % $Id: spm_mip.m 5245 2013-02-06 17:28:06Z guillaume $
  39. %-Get units and grid scaling
  40. %--------------------------------------------------------------------------
  41. try, units; catch, units = {'mm' 'mm' 'mm'}; end
  42. try, M; catch, M = 1; end
  43. Grid = 0.4;
  44. %-Transpose locations if necessary
  45. %--------------------------------------------------------------------------
  46. if size(XYZ,1) ~= 3, XYZ = XYZ'; end
  47. if size(Z,1) ~= 1, Z = Z'; end
  48. if size(M,1) == 1, M = speye(4,4)*M; end
  49. %-Scale & offset point list values to fit in [1/(1+Scal),1]
  50. %--------------------------------------------------------------------------
  51. Z = Z - min(Z);
  52. mx = max(Z);
  53. Scal = 8;
  54. if isempty(mx)
  55. Z = [];
  56. elseif isfinite(mx) && mx
  57. Z = (1 + Scal*Z/mx)/(Scal + 1);
  58. else
  59. Z = ones(1,length(Z));
  60. end
  61. %-Display format
  62. %==========================================================================
  63. % load various grids, DXYZ, CXYZ, scale (see spm_mip_ui and spm_project)
  64. load(char(spm_get_defaults('stats.results.mipmat')));
  65. %-Single slice case
  66. %--------------------------------------------------------------------------
  67. if isempty(units{3}) && ~strcmp(units{2},'mm')
  68. %-2d case: Time-Frequency or Frequency-Frequency
  69. %----------------------------------------------------------------------
  70. mip = 4*grid_trans;
  71. elseif isempty(units{3})
  72. %-2d case
  73. %----------------------------------------------------------------------
  74. mip = 4*grid_trans + mask_trans;
  75. elseif strcmp(units{3},'ms') || strcmp(units{3},'Hz')
  76. %-3d case: Space-time
  77. %----------------------------------------------------------------------
  78. mip = 4*grid_time + mask_trans;
  79. else
  80. %-3d case: Space
  81. %----------------------------------------------------------------------
  82. mip = 4*grid_all + mask_all;
  83. end
  84. %-Create maximum intensity projection
  85. %--------------------------------------------------------------------------
  86. mip = mip/max(mip(:));
  87. c = [0 0 0 ;
  88. 0 0 1 ;
  89. 0 1 0 ;
  90. 0 1 1 ;
  91. 1 0 0 ;
  92. 1 0 1 ;
  93. 1 1 0 ;
  94. 1 1 1 ] - 0.5;
  95. c = c*M(1:3,1:3);
  96. dim = [(max(c) - min(c)) size(mip)];
  97. d = spm_project(Z,round(XYZ),dim,DXYZ,CXYZ);
  98. %if true
  99. mip = max(d,Grid*mip);
  100. mip = rot90((1 - mip)*64);
  101. %else
  102. % mip = rot90((1 - mip)*64);
  103. % d = rot90((1 - d)*64);
  104. % i = repmat(any(d~=64,3),[1 1 3]);
  105. % mip = ind2rgb(ceil(mip),gray(64));
  106. % c = hot(128);
  107. % d = ind2rgb(ceil(d),c(end:-1:65,:));
  108. % mip(i) = d(i);
  109. %end
  110. %-And display it
  111. %--------------------------------------------------------------------------
  112. if ~nargout
  113. image(mip); axis tight; axis off;
  114. end