Home > functions > fmri > vb_spm_to_cortex_org.m

vb_spm_to_cortex_org

PURPOSE ^

SYNOPSIS ^

function [V2ix ,P4 ] = vb_spm_to_cortex_org(spmx3,spmz,V)

DESCRIPTION ^

 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 ,P4 ] = vb_spm_to_cortex_org(spmx3,spmz,V)
0002 %
0003 % Copyright (C) 2011, ATR All Rights Reserved.
0004 % License : New BSD License(see VBMEG_LICENSE.txt)
0005 
0006 error('This function is a canditate to be removed, but invoked.');
0007 
0008 zmin  = min(spmx3(:,3)); 
0009 zmax  = max(spmx3(:,3)); 
0010 zstep = 1;  % searching range of SAG slices
0011 vstep = sqrt(3);  % distance that dipoles are selected
0012 
0013 V2ix  = [];  % index of active dipoles
0014 
0015 %all_calc = fix((zmax-zmin)/zstep)+1;  % for indicator values
0016 
0017 for zi=zmin:zstep:zmax
0018 
0019     % select SPM sources on this slice
0020     pix1 = find(spmx3(:,3)>=zi & spmx3(:,3)<zi+zstep);  
0021 
0022     % select dipoles on this slices
0023     pix2 = find(V(:,3)>=zi & V(:,3)<zi+zstep);  
0024 
0025     % not find
0026     if min(size(pix1))<1 | min(size(pix2))<1, continue; end  
0027 
0028     % find dipoles inside SPM area
0029     pix3=find(V(pix2,1)>=min(spmx3(pix1,1)) & ...
0030               V(pix2,1)<=max(spmx3(pix1,1)) & ...
0031               V(pix2,2)>=min(spmx3(pix1,2)) & ...
0032               V(pix2,2)<=max(spmx3(pix1,2)));  
0033 
0034     % find SPM near each dipole
0035     k=0;  % number of SPM-voxels
0036 
0037     for j=1:size(pix3,1),
0038 
0039         d  = spmx3(pix1,:)-repmat(V(pix2(pix3(j)),:),size(pix1),1);
0040 
0041         dd = d(:,1).^2+d(:,2).^2+d(:,3).^2;
0042 
0043         % the least distance between dipole and SPM-voxel
0044         dy = min(dd);  
0045 
0046         % index of SPM-voxels near one dipole
0047         if dy<vstep^2, 
0048             k       = k+1; 
0049             dix(k) = pix2(pix3(j)); 
0050         end  
0051     end
0052 
0053     % add index of active dipoles
0054     if k~=0, V2ix=unique([V2ix,dix]); end  
0055 
0056     clear dix;
0057 end
0058 
0059 clear zmin zmax zstep pix1 pix2 pix3 d dd dy;
0060 
0061 %
0062 % --- set the active strength of the dipoles
0063 %
0064 fprintf('\n -> calculate activity of dipoles......');
0065 
0066 dok0 = 1;  %size of fMRI voxel
0067 dok1 = 3;  % weight to average spmz
0068 dok2 = 6; % distance whos SPM voxels are selected
0069 j     = 0; 
0070 
0071 % value of Gauss function
0072 for i=dok0/2:dok0:dok2+dok0/2, 
0073     j       = j+1; 
0074     gaf(j) = exp(-i^2/dok1^2); 
0075 end  
0076 
0077 ndip0 = size(V2ix,2);  % number of active dipoles
0078 P3      = [];
0079 
0080 for i=1:ndip0,
0081 
0082     % distance between selected dipoles and SPM
0083     d          = spmx3 - repmat(V(V2ix(i),:),size(spmx3,1),1);
0084 
0085     dd          = sqrt(d(:,1).^2+d(:,2).^2+d(:,3).^2); 
0086     
0087     [ddy,ddi] = sort(dd);
0088     
0089     % averaged SPM strength of each dipoles
0090     P3(i)      = 0; 
0091     wwsum      = 0;
0092     
0093     for l=1:size(ddy,1),
0094         if ddy(l)>dok2, break; end
0095         if 0, ww=exp(-ddy(l)^2/dok1^2);
0096         else, ww=gaf(fix(ddy(l)/dok0)+1); 
0097         end;
0098         
0099         P3(i)=P3(i)+spmz(ddi(l))*ww;
0100     end
0101     
0102     if i==1 | wwsum>wmax, wmax=wwsum; end
0103 end;
0104 
0105 % enhancement
0106 P4=P3./max(P3);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005