0001 function dmri_fs_info_read(freesurfer_dir, fs_info_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 if nargin ~= 2
0033 error('Please check input arguments.');
0034 end
0035
0036
0037
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
0045 [p, f, e] = fileparts(fs_info_file);
0046 if exist(p, 'dir') ~= 7
0047 mkdir(p);
0048 end
0049
0050
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
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
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
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
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
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);