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

dmri_fs_info_read

PURPOSE ^

create freesurfer information file.

SYNOPSIS ^

function dmri_fs_info_read(freesurfer_dir, fs_info_file)

DESCRIPTION ^

 create freesurfer information file.

 [Usage]
    dmri_fs_info_read(freesurfer_dir, output_info_file);

 [Input]
    freesurfer_dir : FreeSurfer subject directory.
      fs_info_file : FreeSurfer information file.


 * fs_info_file Format
    FS_wm.lh_wm_file          : 
         .rh_wm_file          : 
         .lh_smoothwm_file    : 
         .rh_smoothwm_file    : 
         .lh_wm_vertex        : FreeSurfer whitematter verticies(left).
         .rh_wm_vertex        : FreeSurfer whitematter verticies(right).
         .lh_smoothwm_vertex  : FreeSurfer smooth whitematter verticies(left).
         .rh_smoothwm_vertex  : FreeSurfer smooth whitematter verticies(right).
         .lh_cortex_index     : Cortex index list of verticies(left)
         .rh_cortex_index     : Cortex index list of verticies(right).
         .lh_subcortex_index  : SubCortical index list of verticies(left).
         .rh_subcortex_index  : SubCortical index list of verticies(right).

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function dmri_fs_info_read(freesurfer_dir, fs_info_file)
0002 % create freesurfer information file.
0003 %
0004 % [Usage]
0005 %    dmri_fs_info_read(freesurfer_dir, output_info_file);
0006 %
0007 % [Input]
0008 %    freesurfer_dir : FreeSurfer subject directory.
0009 %      fs_info_file : FreeSurfer information file.
0010 %
0011 %
0012 % * fs_info_file Format
0013 %    FS_wm.lh_wm_file          :
0014 %         .rh_wm_file          :
0015 %         .lh_smoothwm_file    :
0016 %         .rh_smoothwm_file    :
0017 %         .lh_wm_vertex        : FreeSurfer whitematter verticies(left).
0018 %         .rh_wm_vertex        : FreeSurfer whitematter verticies(right).
0019 %         .lh_smoothwm_vertex  : FreeSurfer smooth whitematter verticies(left).
0020 %         .rh_smoothwm_vertex  : FreeSurfer smooth whitematter verticies(right).
0021 %         .lh_cortex_index     : Cortex index list of verticies(left)
0022 %         .rh_cortex_index     : Cortex index list of verticies(right).
0023 %         .lh_subcortex_index  : SubCortical index list of verticies(left).
0024 %         .rh_subcortex_index  : SubCortical index list of verticies(right).
0025 %
0026 % Copyright (C) 2011, ATR All Rights Reserved.
0027 % License : New BSD License(see VBMEG_LICENSE.txt)
0028 
0029 %
0030 % --- Previous check
0031 %
0032 if nargin ~= 2
0033     error('Please check input arguments.');
0034 end
0035 
0036 %
0037 % --- Main Procedure
0038 %
0039 disp('Reading FreeSurfer (white/smooth white) matter files...');
0040 if exist(freesurfer_dir, 'dir') ~= 7
0041     error('FreeSurfer directory not found.');
0042 end
0043 
0044 % Create output directory
0045 [p, f, e] = fileparts(fs_info_file);
0046 if exist(p, 'dir') ~= 7
0047     mkdir(p);
0048 end
0049 
0050 % label information created by FreeSurfer
0051 lh_cortex_label_file = [freesurfer_dir, '/label/lh.cortex.label'];
0052 rh_cortex_label_file = [freesurfer_dir, '/label/rh.cortex.label'];
0053 
0054 
0055 % label list file.(Here, only including cortex label.)
0056 label_list_lh_file = tempname;
0057 label_list_rh_file = tempname;
0058 make_list_file(label_list_lh_file, lh_cortex_label_file);
0059 make_list_file(label_list_rh_file, rh_cortex_label_file);
0060 
0061 %
0062 % --- Convert binary to ascii format (whitematter, smooth white matter)
0063 %
0064 lh_white_matter_file = [freesurfer_dir, '/surf/lh.white'];
0065 rh_white_matter_file = [freesurfer_dir, '/surf/rh.white'];
0066 lh_white_matter_asc_file = [p, '/lh_whitematter.asc'];
0067 rh_white_matter_asc_file = [p, '/rh_whitematter.asc'];
0068 
0069 lh_smooth_white_matter_file = [freesurfer_dir, '/surf/lh.smoothwm'];
0070 rh_smooth_white_matter_file = [freesurfer_dir, '/surf/rh.smoothwm'];
0071 lh_smooth_white_matter_asc_file = [p, '/lh_smooth_whitematter.asc'];
0072 rh_smooth_white_matter_asc_file = [p, '/rh_smooth_whitematter.asc'];
0073 
0074 convert_bin_to_asc(lh_white_matter_file, lh_white_matter_asc_file);
0075 convert_bin_to_asc(rh_white_matter_file, rh_white_matter_asc_file);
0076 convert_bin_to_asc(lh_smooth_white_matter_file, lh_smooth_white_matter_asc_file);
0077 convert_bin_to_asc(rh_smooth_white_matter_file, rh_smooth_white_matter_asc_file);
0078 
0079 
0080 % Add Cortex label information to White matter surface file(4th)
0081 tmp_lh_labelled_gii_file = [p, '/lh_labelled_whitematter.gii'];
0082 tmp_rh_labelled_gii_file = [p, '/rh_labelled_whitematter.gii'];
0083 lh_labelled_asc_file = [p, '/lh_labelled_whitematter.asc'];
0084 rh_labelled_asc_file = [p, '/rh_labelled_whitematter.asc'];
0085 command3 = ['label2surf --surf=' lh_white_matter_asc_file, ...
0086             ' --out=' tmp_lh_labelled_gii_file, ...
0087             ' --labels=' label_list_lh_file];
0088 dmri_system(command3);
0089 command3_1 = ['surf2surf -i ' tmp_lh_labelled_gii_file, ...
0090               ' -o ' lh_labelled_asc_file, ...
0091               ' --outputtype=ASCII'];
0092 dmri_system(command3_1);
0093 
0094 
0095 command4 = ['label2surf --surf=' rh_white_matter_asc_file, ...
0096             ' --out=' tmp_rh_labelled_gii_file, ...
0097             ' --labels=' label_list_rh_file];
0098 dmri_system(command4);
0099 command4_1 = ['surf2surf -i ' tmp_rh_labelled_gii_file, ...
0100               ' -o ' rh_labelled_asc_file, ...
0101               ' --outputtype=ASCII'];
0102 dmri_system(command4_1);
0103 
0104 % Read Labeled white matter surface file
0105 [lh_S, lh_v] = read_asc(lh_labelled_asc_file);
0106 [rh_S, rh_v] = read_asc(rh_labelled_asc_file);
0107 
0108 [lh_S2, lh_v2] = read_asc(lh_smooth_white_matter_asc_file);
0109 [rh_S2, rh_v2] = read_asc(rh_smooth_white_matter_asc_file);
0110 
0111 % Create FreeSurfer information
0112 FS_wm.lh_wm_asc_file       = lh_white_matter_asc_file;
0113 FS_wm.rh_wm_asc_file       = rh_white_matter_asc_file;
0114 FS_wm.lh_smoothwm_asc_file = lh_smooth_white_matter_asc_file;
0115 FS_wm.rh_smoothwm_asc_file = rh_smooth_white_matter_asc_file;
0116 FS_wm.lh_wm_vertex         = lh_v(:, 1:3);
0117 FS_wm.rh_wm_vertex         = rh_v(:, 1:3);
0118 FS_wm.lh_smoothwm_vertex   = lh_v2(:, 1:3);
0119 FS_wm.rh_smoothwm_vertex   = rh_v2(:, 1:3);
0120 FS_wm.lh_cortex_index      = find(lh_v(:, 4) == 1)';
0121 FS_wm.rh_cortex_index      = find(rh_v(:, 4) == 1)';
0122 FS_wm.lh_subcortex_index   = find(lh_v(:, 4) ~= 1)';
0123 FS_wm.rh_subcortex_index   = find(rh_v(:, 4) ~= 1)';
0124 
0125 save(fs_info_file, 'FS_wm');
0126 disp(['Saved:' fs_info_file]);
0127 
0128 
0129 function make_list_file(label_list_file, label_file)
0130 
0131 command = ['echo ' label_file ' >' label_list_file];
0132 system(command);
0133 
0134 function convert_bin_to_asc(bin_file, asc_file)
0135 
0136 command  = ['mris_convert ', bin_file, ' ', asc_file];
0137 dmri_system(command);

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