Home > vbmeg > functions > tool_box > dmri_processor > functions > dmri_parcel_to_label_file.m

dmri_parcel_to_label_file

PURPOSE ^

Make .label files for using as ROIs of anatomical connectivity matrix

SYNOPSIS ^

function dmri_parcel_to_label_file(parcels_file, fs_info_file, output_dir)

DESCRIPTION ^

 Make .label files for using as ROIs of anatomical connectivity matrix

 [Usage]
    dmri_parcel_to_label_file(parcels_file, fs_info_file);

 [Input]
    parcels_file : parcels information file.
    fs_info_file : freesurfer infomation file.
      output_dir : label file output directory.

 [Output]
    none

 [Note]
    Output label files are written for FSL.
    They contain Freesurfer cortical indicies.

    * left and right parcels
      parcel1.label
      parcel2.label
      ...
      parcelN.label

    * Subcortical label
      lh/rh.subcortex.label

    originally created by M.Fukushima

 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 dmri_parcel_to_label_file(parcels_file, fs_info_file, output_dir)
0002 % Make .label files for using as ROIs of anatomical connectivity matrix
0003 %
0004 % [Usage]
0005 %    dmri_parcel_to_label_file(parcels_file, fs_info_file);
0006 %
0007 % [Input]
0008 %    parcels_file : parcels information file.
0009 %    fs_info_file : freesurfer infomation file.
0010 %      output_dir : label file output directory.
0011 %
0012 % [Output]
0013 %    none
0014 %
0015 % [Note]
0016 %    Output label files are written for FSL.
0017 %    They contain Freesurfer cortical indicies.
0018 %
0019 %    * left and right parcels
0020 %      parcel1.label
0021 %      parcel2.label
0022 %      ...
0023 %      parcelN.label
0024 %
0025 %    * Subcortical label
0026 %      lh/rh.subcortex.label
0027 %
0028 %    originally created by M.Fukushima
0029 %
0030 % Copyright (C) 2011, ATR All Rights Reserved.
0031 % License : New BSD License(see VBMEG_LICENSE.txt)
0032 
0033 %
0034 % --- Previous check
0035 %
0036 if nargin ~= 3
0037     error('Please check input arguments.');
0038 end
0039 if exist(parcels_file, 'file') ~= 2
0040     error(sprintf('Specified parcels file not found : %s', parcels_file));
0041 end
0042 if exist(fs_info_file, 'file') ~= 2
0043     error(sprintf('Specified freesurfer information file not found: %s', fs_info_file));
0044 end
0045 if exist(fs_info_file, 'dir') ~= 7
0046     mkdir(output_dir);
0047 end
0048 
0049 %
0050 % --- Main Procedure
0051 %
0052 format long
0053 
0054 fs = load(fs_info_file);
0055 
0056 % File names
0057 lhascfile = fs.FS_wm.lh_smoothwm_asc_file;
0058 rhascfile = fs.FS_wm.rh_smoothwm_asc_file;
0059 
0060 % Read .asc file
0061 [l_S, l_v, l_f] = read_asc(lhascfile);
0062 [r_S, r_v, r_f] = read_asc(rhascfile);
0063 
0064 load(parcels_file);
0065 size_left = length(lh_cortex_id);
0066 Nlabel = length(lh_cortex_id) + length(rh_cortex_id);
0067 
0068 cortex_id = [lh_cortex_id; rh_cortex_id];
0069 
0070 % Create label files
0071 fprintf('Now putting label files into %s\n', output_dir);
0072 for nv = 1:Nlabel
0073   original_ind = cortex_id{nv};
0074 
0075   if nv <= size_left
0076     lxyz  = l_v(original_ind, 1:3);
0077     lvals = l_v(original_ind, 4);
0078   else
0079     lxyz  = r_v(original_ind, 1:3);
0080     lvals = r_v(original_ind, 4);
0081   end
0082 
0083   % Output file name
0084   labelfile = fullfile(output_dir, filesep, ['parcel' num2str(nv) '.label']);
0085   lindex = original_ind - 1; % 0-based, M.Fukushima 2012/06/11
0086   
0087   % Write .label file
0088   ok = write_label(lindex, lxyz, lvals, labelfile, parcels_file);
0089   if ok ~=1
0090     error('Writing .label file is failed!!');
0091   end
0092 end
0093 
0094 fprintf('done.\n');
0095 
0096 
0097 %
0098 % --- Create subcortex label
0099 %
0100 original_ind = fs.FS_wm.lh_subcortex_index;
0101 lxyz  = l_v(original_ind, 1:3);
0102 lvals = l_v(original_ind, 4);
0103 labelfile = fullfile(output_dir, filesep, 'lh.subcortex.label');
0104 
0105 lindex = original_ind - 1; % 0-based, M.Fukushima 2012/06/11
0106 ok = write_label(lindex, lxyz, lvals, labelfile, parcels_file);
0107 
0108 original_ind = fs.FS_wm.rh_subcortex_index;
0109 lxyz  = r_v(original_ind, 1:3);
0110 lvals = r_v(original_ind, 4);
0111 labelfile = fullfile(output_dir, filesep, 'rh.subcortex.label');
0112 
0113 lindex = original_ind - 1; % 0-based, M.Fukushima 2012/06/11
0114 ok = write_label(lindex, lxyz, lvals, labelfile, parcels_file);

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