Transform anatomical label in standard space to an individual brain -- Usage [B, Vspm] = vb_map_mask_image(analyzefile,mask_file,snfile) -- Input analyzefile : Subject analyzefile file mask_file : Mask image file snfile : Created by SPM normalization (Personal-> MNI-template). The normalize transformation is contained. -- Output avw.img : Transformed mask image (SPM-right) avw.hdr.dime.dim(2:4) : image dimension avw.hdr.dime.pixdim(2:4) : voxel size [mm] Vspm{n}.xyz : SPM-right-[m]-coordinate list Vspm{n}.label : region label -- Function required spm_dctmtx : vb_unsn : back transformation (by Gohda-san) --- NOTE 1 ---- It is highly recommended to recalculate the normalize transformation by spm2 !!! --- NOTE 2 ---- Flip can not be considered in this routine. 2007/06/09 Masa-aki Sato Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [avw, Vspm] = vb_map_mask_image(analyzefile,mask_file,snfile) 0002 % Transform anatomical label in standard space to an individual brain 0003 % -- Usage 0004 % [B, Vspm] = vb_map_mask_image(analyzefile,mask_file,snfile) 0005 % 0006 % -- Input 0007 % analyzefile : Subject analyzefile file 0008 % mask_file : Mask image file 0009 % snfile : Created by SPM normalization (Personal-> MNI-template). 0010 % The normalize transformation is contained. 0011 % 0012 % -- Output 0013 % avw.img : Transformed mask image (SPM-right) 0014 % avw.hdr.dime.dim(2:4) : image dimension 0015 % avw.hdr.dime.pixdim(2:4) : voxel size [mm] 0016 % 0017 % Vspm{n}.xyz : SPM-right-[m]-coordinate list 0018 % Vspm{n}.label : region label 0019 % -- Function required 0020 % spm_dctmtx : 0021 % vb_unsn : back transformation (by Gohda-san) 0022 % 0023 % --- NOTE 1 ---- 0024 % It is highly recommended to recalculate the normalize transformation by 0025 % spm2 !!! 0026 % --- NOTE 2 ---- 0027 % Flip can not be considered in this routine. 0028 % 0029 % 2007/06/09 Masa-aki Sato 0030 % 0031 % Copyright (C) 2011, ATR All Rights Reserved. 0032 % License : New BSD License(see VBMEG_LICENSE.txt) 0033 0034 Nmax = 100000; 0035 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 %%%%%%%%%%%%%%%%%%%% Don't modify %%%%%%%%%%%%%%%%%%%%%%%%%%% 0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0039 0040 %%% 0041 %%% Backward coordinate transformation 0042 %%% from the template brain to a subject's brain 0043 %%% Template file is neurological format (right handed spm). 0044 0045 % Read mask image 0046 % XYZmni - 3 x n matrix of XYZ locations 0047 % mm-coordinates in atlas-template (origin : MNI-space origin) 0048 % avw.img - 3D image data 0049 0050 load(mask_file,'avw', 'XYZmni','Indx'); 0051 0052 N = length(Indx); 0053 0054 % MNI-coordinate for Indx{n} 0055 %for n=1:N 0056 % XYZ{n} = XYZmni(:,Indx{n}.ix); 0057 %end 0058 0059 % Extract mask region 0060 mni_id = find(avw.img(:) ~= 0); 0061 Nmask = length(mni_id); 0062 Z = avw.img(mni_id); 0063 0064 % MNI-coordinates in atlas-template for brain region 0065 XYZmni = XYZmni(:,mni_id); 0066 0067 fprintf('# of template points = %d\n',Nmask) 0068 fprintf('--- Back transformation to subject-image \n'); 0069 0070 % Back transformation to subject image 0071 % pXYZ : SPM-right-[m]-coordinate in subject image 0072 0073 sn = load(deblank(snfile)); 0074 0075 % SPM-oordinate for Indx{n} 0076 for n=1:N 0077 Vspm{n}.xyz = vb_unsn( Indx{n}.xyz, sn)'*0.001; 0078 Vspm{n}.F = Indx{n}.F; 0079 Vspm{n}.label = Indx{n}.label; 0080 end 0081 0082 if Nmask > Nmax, 0083 pXYZ = zeros(Nmask,3); 0084 Ndata = 0; 0085 while Ndata < Nmask 0086 n1 = Ndata + 1; 0087 n2 = Ndata + Nmax; 0088 if n2 > Nmask, n2 = Nmask; end; 0089 Ndata = n2; 0090 0091 xyz = XYZmni(:,n1:n2); 0092 pXYZ(n1:n2,:) = vb_unsn(xyz,sn)'*0.001; 0093 end 0094 else 0095 pXYZ = vb_unsn(XYZmni,sn)'*0.001; 0096 end 0097 0098 fprintf('--- Mapping mask image to subject-brain \n'); 0099 0100 [Vdim, Vsize] = analyze_hdr_read(analyzefile); 0101 0102 pXYZ = vb_spm_right_to_analyze_right(pXYZ,Vdim,Vsize); 0103 0104 if Vsize(1)==1 & Vsize(2)==1 & Vsize(3)==1 , 0105 [pXYZ, Z] = vb_make_upsample_vertex(pXYZ, Z); 0106 end 0107 0108 B = vb_make_mask_from_vertex(Vdim, pXYZ, Z); 0109 0110 avw.hdr.dime.dim = [4 Vdim(:)' 1]; 0111 avw.hdr.dime.pixdim = [1 Vsize(:)' 1]; 0112 avw.img = B; 0113 0114 return 0115 % 0116 % if coordinate system is left-handed spm, flip x-direction coordinate 0117 % pXYZ(:,1) = -pXYZ(:,1) ; 0118 0119 % Find nearest point in atlas for each vertex 'V' 0120 % [V] = vb_load_cortex(brainfile); % [m] 0121 % [indx] = vb_find_nearest_point(pXYZ, V*1000); 0122 0123 %%% 0124 %%% Map MNI-coordinate to individual's cortical surface 0125 %%%