Home > vbmeg > functions > fmri > vb_spm_to_cortex.m

vb_spm_to_cortex

PURPOSE ^

Select the dipoles around the active area in fMRI

SYNOPSIS ^

function [V2ix ,P3 ] = vb_spm_to_cortex(spmx3, spmz, V, PARAM)

DESCRIPTION ^

 Select the dipoles around the active area in fMRI

 ---- Output
   V2ix   : Vertex indices corresponding to SPM activity points
   P3     : T-value mapped onto cortical surface (normalized so that
            maximum=1)
 ---- Input
   spmx3  : SPM point coordinate [x, y, z] (mm)
   spmz   : t-value
   V      : 3D coordinate of vertex number n  (#Vertex*3) 

 Originaly written by S.Kajihara
 Ver 1.0  modified by M. Sato  2003-3-15
 2005-08-30 K. Shibata 
 * scale of t-value is preserved.
 2008-07-23 Taku Yoshioka (Radius check)
 2009-05-08 Taku Yoshioka (Radius=0 availale)
 2011-06-20 taku-y
  [minor] Progress message was added. 

---- Parameter setting ----
 A vertex point of cortical surface V(n) is chosen as an activity when 
 it is located inside the sphere of radius 'SPM_Radius' with the center
 V(n).

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [V2ix ,P3 ] = vb_spm_to_cortex(spmx3, spmz, V, PARAM)
0002 % Select the dipoles around the active area in fMRI
0003 %
0004 % ---- Output
0005 %   V2ix   : Vertex indices corresponding to SPM activity points
0006 %   P3     : T-value mapped onto cortical surface (normalized so that
0007 %            maximum=1)
0008 % ---- Input
0009 %   spmx3  : SPM point coordinate [x, y, z] (mm)
0010 %   spmz   : t-value
0011 %   V      : 3D coordinate of vertex number n  (#Vertex*3)
0012 %
0013 % Originaly written by S.Kajihara
0014 % Ver 1.0  modified by M. Sato  2003-3-15
0015 % 2005-08-30 K. Shibata
0016 % * scale of t-value is preserved.
0017 % 2008-07-23 Taku Yoshioka (Radius check)
0018 % 2009-05-08 Taku Yoshioka (Radius=0 availale)
0019 % 2011-06-20 taku-y
0020 %  [minor] Progress message was added.
0021 %
0022 %---- Parameter setting ----
0023 % A vertex point of cortical surface V(n) is chosen as an activity when
0024 % it is located inside the sphere of radius 'SPM_Radius' with the center
0025 % V(n).
0026 %
0027 % Copyright (C) 2011, ATR All Rights Reserved.
0028 % License : New BSD License(see VBMEG_LICENSE.txt)
0029 
0030 SPM_Radius2   = PARAM.SPM_Radius^2 ;% maximum distance for point selection
0031 SPM_zstep      = PARAM.SPM_zstep  ;    % slice step size in z-direction
0032 
0033 % Gauss filter parameter to average SPM t-value
0034 Gauss_radius2 = PARAM.Gauss_radius^2;% half-width of Gaussian filter
0035 Gauss_max      = PARAM.Gauss_max ;     % maximum distance for averaging
0036 Gauss_max2      = PARAM.Gauss_max^2 ;     % maximum distance for averaging
0037 
0038 % Search range of cortex slices in z-direction
0039 zstep = SPM_zstep;                      % slice step size in z-direction
0040 zmin  = min(V(:,3)) - zstep/2; 
0041 zmax  = max(V(:,3)) + zstep/2; 
0042 spmz  = spmz(:);
0043 
0044 %---- Parameter setting end----
0045 V2ix  = [];                                % Index of active dipoles
0046 P3      = [];                                % Strength of active dipoles
0047 
0048 % Loop for slices in z-direction
0049 
0050 h       = waitbar(0,'Select dipoles');
0051 prg     = 0;
0052 prg_all = zmax-zmin;
0053 vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0054 
0055 for zi=zmin:zstep:zmax
0056   % select dipoles on this slices
0057   pixz = find( V(:,3) >= zi & V(:,3) < zi+zstep );  
0058 
0059   % select SPM sources near this slice
0060   spix = find(spmx3(:,3) >= zi - Gauss_max ...
0061               & spmx3(:,3) <= zi + Gauss_max + zstep);  
0062 
0063   % No SPM point or dipole on this slice
0064   if min(size(spix))<1 | min(size(pixz))<1, continue; end  
0065     
0066   % Find dipoles inside SPM active area
0067   pixy = find(V(pixz,1) >= min(spmx3(spix,1)) - Gauss_max ...
0068               & V(pixz,1) <= max(spmx3(spix,1)) + Gauss_max ...
0069               & V(pixz,2) >= min(spmx3(spix,2)) - Gauss_max ...
0070               & V(pixz,2) <= max(spmx3(spix,2)) + Gauss_max );  
0071 
0072   % Find neighboring SPM-voxel for each dipole
0073 
0074 
0075   % Index for repmat
0076   indxV = 1:3;
0077   indxV = indxV( ones( length(spix), 1 ), : );
0078 
0079   Nnext = size(pixy,1);                        
0080   spmxd = spmx3(spix,:);
0081 
0082   % Loop for candidate dipoles in this slice
0083   for j=1:Nnext,
0084     
0085     % Distance between dipole and SPM-voxel
0086     pix = pixz(pixy(j));                 % candidate dipole index
0087     Vp    = V(pix,:);
0088     d    = spmxd - Vp(indxV);
0089     dd    = sum(d.^2 , 2 );
0090 
0091     % Radius check (08-07-23 Taku Yoshioka)
0092     if Gauss_max2<SPM_Radius2, Gauss_max2 = SPM_Radius2; end
0093         
0094     % index of dipole near SPM-voxel
0095     ix    = find( dd <= Gauss_max2 );        % Maximum Averaging radius
0096     ixx    = find( dd <  SPM_Radius2 );    % Maximum Selection radius
0097         
0098     % Check if there are active SPM-voxel in the selection area
0099     if ~isempty( ixx ),
0100         
0101       % Add active dipole index
0102       V2ix = [V2ix ; pix]; 
0103 
0104       % Gauss-averaged SPM strength for the dipole
0105       if Gauss_radius2 > 0, 
0106         Pv = sum(spmz(spix(ix)).*exp(-dd(ix)/Gauss_radius2)) ...
0107              /sum(exp(-dd(ix)/Gauss_radius2));
0108       else
0109         Pv = sum(spmz(spix(ix)))./length(ix);
0110       end
0111       P3     = [P3 ; Pv];
0112       
0113     end
0114   end
0115   
0116   waitbar((zi-zmin)/(zmax-zmin));
0117   for ii=1:15; vb_disp_nonl(sprintf('\b')); end
0118   vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0119   prg = zi-zmin;
0120 end
0121 
0122 % Normalization
0123 % P3    = P3./max(P3);
0124 
0125 close(h);
0126 drawnow;
0127 vb_disp_nonl(sprintf('\n'));
0128 
0129 return;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005