Home > vbmeg > functions > tool_box > atlas2vb_dir > vb_atlas2vb_aal.m

vb_atlas2vb_aal

PURPOSE ^

vb_atlas2vb_aal create an area indices

SYNOPSIS ^

function vb_atlas2vb_aal(parm)

DESCRIPTION ^

 vb_atlas2vb_aal create an area indices
   based on the Automated anatomical labeling 'aal'-atlas
 ---- Syntax
 vb_atlas2vb_aal(parm)

 ---- Input
 fields in 'parm'
 atlas_dir      : Dir of atlas file 'aal.img'
 save_areafile  : Area file saved
 save_atlasfile : Atlas file saved
 save_xyzfile   : MNI & Talairach coordinate file
 brainfile      : brain file;


 --- Function required  
  explode      : string manupilation 

 ---- NOTE -----
 When using the normalize transformation matrix created by 'spm99',  
 back transformation results with a little shift 
 toward X(Left-Right) direction compared with brain file.
 It is highly recommended to recalculate 
 the transformation matrix by spm2 !!!

 2005/03/03 OY
 2005/03/28 modified 
 2005/04/21 second part modified
 2005/09/09 ver.030b compatible
 2005/12/22 M.Sato
 2006/2/3   M.Sato
 2006/11/14 M.Sato
 2007/03/05 OY
 * MNI coordinate is stored in brainfile.
 * save_xyzfile is removed.
 * A label for 'Corpus' is NaN.
 2009-01-05 Taku Yoshioka
   Supression of confirmation dialog

 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    vb_atlas2vb_aal(parm)
0002 % vb_atlas2vb_aal create an area indices
0003 %   based on the Automated anatomical labeling 'aal'-atlas
0004 % ---- Syntax
0005 % vb_atlas2vb_aal(parm)
0006 %
0007 % ---- Input
0008 % fields in 'parm'
0009 % atlas_dir      : Dir of atlas file 'aal.img'
0010 % save_areafile  : Area file saved
0011 % save_atlasfile : Atlas file saved
0012 % save_xyzfile   : MNI & Talairach coordinate file
0013 % brainfile      : brain file;
0014 %
0015 %
0016 % --- Function required
0017 %  explode      : string manupilation
0018 %
0019 % ---- NOTE -----
0020 % When using the normalize transformation matrix created by 'spm99',
0021 % back transformation results with a little shift
0022 % toward X(Left-Right) direction compared with brain file.
0023 % It is highly recommended to recalculate
0024 % the transformation matrix by spm2 !!!
0025 %
0026 % 2005/03/03 OY
0027 % 2005/03/28 modified
0028 % 2005/04/21 second part modified
0029 % 2005/09/09 ver.030b compatible
0030 % 2005/12/22 M.Sato
0031 % 2006/2/3   M.Sato
0032 % 2006/11/14 M.Sato
0033 % 2007/03/05 OY
0034 % * MNI coordinate is stored in brainfile.
0035 % * save_xyzfile is removed.
0036 % * A label for 'Corpus' is NaN.
0037 % 2009-01-05 Taku Yoshioka
0038 %   Supression of confirmation dialog
0039 %
0040 % Copyright (C) 2011, ATR All Rights Reserved.
0041 % License : New BSD License(see VBMEG_LICENSE.txt)
0042 
0043 %
0044 % ---- Define aal-atlas
0045 %
0046 
0047 % Max value corresponding to Cerebrum cortex region in aal-atlas
0048 %  1-90: Cerebrum, 91-108: Cerebellum, 109-116: Vermis
0049 MaxLabel   = 90;    
0050 
0051 atlas_dir  = parm.atlas_dir;
0052 atlas_id   = 'aal';
0053 atlas_text = [atlas_dir 'aal.txt'];
0054 atlas_file = [atlas_dir 'aal.img'];
0055 brainfile  = parm.brainfile;
0056 
0057 save_areafile  = parm.save_areafile;
0058 save_atlasfile = parm.save_atlasfile;
0059 
0060 % Max radius to check minimum distance to corresponding point [mm]
0061 if    isfield(parm,'Rlimit')
0062     Rlimit = parm.Rlimit;
0063 else
0064     Rlimit = 4; 
0065 end
0066 
0067 % Max radius to search corresponding point [mm] in the 1st-step
0068 if    isfield(parm,'Rmax')
0069     Rmax = parm.Rmax;
0070 else
0071     Rmax = 2; 
0072 end
0073 
0074 % In the 1st-step, nearest point is searched within Rmax
0075 % In the 2nd-step, nearest point is searched for all candidates
0076 % This value determine, efficiency of search,
0077 % but does not change the result
0078 
0079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0080 %%%%%%%%%%%%%%%%%%%% Don't modify %%%%%%%%%%%%%%%%%%%%%%%%%%%
0081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0082 
0083 %%% Template file is neurological format (right handed spm).
0084 
0085 % ----- Corpus label
0086 corpus_key   = 'Corpus';
0087 corpus_label = NaN;
0088 
0089 %
0090 % ---- Load MNI-mm-coordinate for subject brain (should be calculated before)
0091 %
0092 warning('off', 'MATLAB:load:variableNotFound');
0093 load(brainfile, 'Vmni','derr');
0094 warning('on', 'MATLAB:load:variableNotFound');
0095 if ~exist('derr', 'var'), derr = zeros(size(Vmni,1), 1); end
0096 XYZmm = Vmni*1000;   % mm
0097 dd    = derr*1000;   % mm
0098 
0099 [Npoint, NdipoleL] = vb_load_cortex_info(brainfile);
0100 Vlabel     = zeros(Npoint,1);
0101 dd_label = zeros(Npoint,1);
0102 
0103 
0104 Vindx = [1:Npoint];
0105 %
0106 % ----- Remove corpus
0107 %
0108 % fprintf('---  Remove corpus region\n');
0109 % [Vindx, Iremove] = vb_remove_corpus_run(brainfile);
0110 % Vlabel(Iremove)  = corpus_label;
0111 %
0112 % fprintf('# of Corpus points = %d\n',length(Iremove))
0113 
0114 %
0115 % ---- Load Atlas template file
0116 %
0117 
0118 % Read image-header
0119 [dim, Trans, XYZmm0] = vb_get_image_info(atlas_file);
0120 
0121 % Read atlas-template image
0122 % Z    - 3D image data
0123 %Zlabel = read_image(atlas_file);
0124 
0125 avw = avw_img_read(atlas_file);
0126 Zlabel = avw.img;
0127 
0128 % Zlabel - 3D image data (label value)
0129 % XYZmm0 - 3 x n matrix of XYZ locations
0130 %        mm-coordinates in atlas-template (origin is specified by image file)
0131 Zlabel = Zlabel(:);
0132 
0133 % Extract labeled region
0134 mni_id = find(Zlabel ~= 0); 
0135 Zlabel = Zlabel(mni_id);
0136 XYZmm0 = XYZmm0(:,mni_id)';
0137 
0138 %
0139 % ---- Left brain (Left label is odd integer in 'aal')
0140 %
0141 ix_L  = find( mod( Zlabel, 2 ) == 1 & Zlabel < MaxLabel);
0142 ix_LV = Vindx( Vindx <= NdipoleL );
0143 
0144 fprintf('# of Left template points = %d\n',length(ix_L))
0145 fprintf('# of Left brain points    = %d\n',length(ix_LV))
0146 
0147 fprintf('--- Mapping Atlas-label onto 2D cortical surface \n');
0148 
0149 % Find nearest labeled point in atlas
0150 [indx, dd_tmp] = ...
0151         vb_find_nearest_point(XYZmm0(ix_L,:), XYZmm(ix_LV,:), Rmax, 100, 0, 1);
0152 
0153 fprintf('# of matched Left brain points    = %d\n',length(indx))
0154 
0155 % Find points whose minimum distance to atlas brain region is less than Rlimit
0156 ix_match = find( dd(ix_LV) <= Rlimit & dd_tmp < Rmax & indx > 0 );
0157 %ix_match = find( dd(ix_LV) <= Rlimit & dd_tmp < Rmax );
0158 
0159 fprintf('# of close points in Left brain   = %d\n',length(ix_match))
0160 
0161 % Map label to subject cortex
0162 Vlabel(ix_LV(ix_match)) = Zlabel(ix_L(indx(ix_match)));
0163 dd_label(ix_LV) = dd_tmp;
0164 %
0165 % ---- Right brain (Right label is even integer in 'aal')
0166 %
0167 ix_R  = find( mod( Zlabel, 2 ) == 0 & Zlabel <= MaxLabel);
0168 ix_RV = Vindx( Vindx > NdipoleL );
0169 
0170 fprintf('# of Right template points = %d\n',length(ix_R))
0171 fprintf('# of Right brain points    = %d\n',length(ix_RV))
0172 
0173 fprintf('--- Mapping Atlas-label onto 2D cortical surface \n');
0174 
0175 % Find nearest labeled point in atlas
0176 [indx, dd_tmp] = ...
0177         vb_find_nearest_point(XYZmm0(ix_R,:), XYZmm(ix_RV,:), Rmax, 100, 0, 1);
0178 
0179 fprintf('# of matched Right brain points    = %d\n',length(indx))
0180 
0181 % Find points whose minimum distance to atlas brain region is less than Rlimit
0182 ix_match = find( dd(ix_RV) <= Rlimit & dd_tmp < Rmax & indx > 0 );
0183 %ix_match = find( dd(ix_RV) <= Rlimit & dd_tmp < Rmax );
0184 
0185 fprintf('# of close points in Right brain   = %d\n',length(ix_match))
0186 
0187 % Map label to subject cortex
0188 Vlabel(ix_RV(ix_match)) = Zlabel(ix_R(indx(ix_match)));
0189 dd_label(ix_RV) = dd_tmp;
0190 
0191 % Fill label for large distant point
0192 ixz    = find( dd_label >= Rmax );
0193 fprintf('# of unlabeld point = %d\n', length(ixz))
0194 
0195 %fprintf('Filling unlabeled points\n')
0196 %Vlabel = vb_fill_atlas_label(brainfile, Vlabel, ixz, Rlimit);
0197 
0198 %
0199 % ---- Save labeled area
0200 %
0201 Nlabel = sum( Vlabel ~= 0 );    % # of labeled points
0202 fprintf('# of all vertex     = %d\n',Npoint)
0203 fprintf('# of cortex  points = %d\n',length(Vindx))
0204 fprintf('# of labeled points = %d\n',Nlabel)
0205 
0206 % Read atlas text file and extract area keys.
0207 [label, label_name] = vb_read_atlas_label(atlas_text);
0208 
0209 % Add Corpus label
0210 Narea = length(label);
0211 label(Narea+1) = corpus_label;
0212 label_name{Narea+1} = corpus_key;
0213 
0214 % Intensity of 'Act.xxP' is the label for each vertex
0215 Atlas.key = [atlas_id];
0216 Atlas.xxP = Vlabel;
0217 Atlas.label      = label;
0218 Atlas.label_name = label_name;
0219 Atlas.dd_label   = dd_label;
0220 
0221 % Save label as actfile
0222 fprintf('Save the atlas file as "%s"  \n', save_atlasfile);
0223 vb_add_act(save_atlasfile,Atlas,[],false);
0224 
0225 % Save area label into area file
0226 fprintf('Save the area file as "%s" \n', save_areafile);
0227 
0228 vb_save_atlas_label(save_areafile,Vlabel,label,label_name);
0229 
0230 clear Zlabel Vlabel XYZmm0 XYZmm Zlabel

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