0001 function dmri_wm_FA_volume_create(fs_dir, ...
0002 ref_struct_niigz_file, ...
0003 ref_FA_niigz_file, trans_info_dir, ...
0004 output_wm_niigz_file)
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 ~= 5
0033 error('Please check input arguments.');
0034 end
0035
0036 if exist(fs_dir, 'dir') ~= 7
0037 error('Specified fs_dir not found.');
0038 end
0039 if exist(ref_struct_niigz_file, 'file') ~= 2
0040 error('Specified ref_struct_niigz_file not found.');
0041 end
0042 if exist(ref_FA_niigz_file, 'file') ~= 2
0043 error('Specified ref_FA_niigz_file not found.');
0044 end
0045 if exist(trans_info_dir, 'dir') ~= 7
0046 error('Specified trans_info_dir not found.');
0047 end
0048
0049
0050
0051
0052 disp('Creating whitematter volume on FA coordinate system.');
0053 if exist(output_wm_niigz_file, 'file') == 2
0054 copyfile(output_wm_niigz_file, [output_wm_niigz_file, '.bak']);
0055 delete(output_wm_niigz_file);
0056 end
0057
0058 work_dir = tempname;
0059 mkdir(work_dir);
0060
0061
0062
0063
0064
0065 lh_asc_file = fullfile(fs_dir, filesep, '/bem/lh.smoothwm.asc');
0066 rh_asc_file = fullfile(fs_dir, filesep, '/bem/rh.smoothwm.asc');
0067
0068 [l_S, l_v, l_f] = read_asc(lh_asc_file);
0069 [r_S, r_v, r_f] = read_asc(rh_asc_file);
0070
0071
0072 lindex = 0:(size(l_v,1) + size(r_v,1) - 1);
0073 lxyz = [l_v(:,1:3)' r_v(:,1:3)']';
0074 lvals = [l_v(:,4)' r_v(:,4)']';
0075
0076 wm_label_file = fullfile(work_dir, filesep, 'wm.label');
0077 ok = write_label(lindex, lxyz, lvals, wm_label_file, fs_dir);
0078 if ok ~=1
0079 error('Writing .label file is failed!!');
0080 end
0081
0082
0083
0084
0085 lh_wm_file = fullfile(fs_dir, filesep, 'surf/lh.smoothwm');
0086 rh_wm_file = fullfile(fs_dir, filesep, 'surf/rh.smoothwm');
0087
0088 tmp_wm_lh_fill_file = fullfile(work_dir, filesep, 'tmp_wm_lhfill.nii.gz');
0089 tmp_wm_rh_fill_file = fullfile(work_dir, filesep, 'tmp_wm_rhfill.nii.gz');
0090
0091
0092 cmd = ['mris_fill', ...
0093 ' -c -r 1', ...
0094 ' ', lh_wm_file, ...
0095 ' ', tmp_wm_lh_fill_file];
0096
0097 dmri_system(cmd, '-echo');
0098
0099 cmd = ['mris_fill', ...
0100 ' -c -r 1', ...
0101 ' ', rh_wm_file, ...
0102 ' ', tmp_wm_rh_fill_file];
0103 dmri_system(cmd, '-echo');
0104
0105
0106 tmp_wm_fill_file = fullfile(work_dir, filesep, 'tmp_wm_fill.nii.gz');
0107 dmri_add_images(tmp_wm_lh_fill_file, ...
0108 tmp_wm_rh_fill_file, ...
0109 tmp_wm_fill_file);
0110
0111
0112 brain_on_FS_coord_file = fullfile(fs_dir, filesep, 'mri/brain.nii.gz');
0113 tmp_wm_file = fullfile(work_dir, filesep, 'tmp_wm.nii.gz');
0114
0115 cmd = ['mri_label2vol', ...
0116 ' --label ', wm_label_file, ...
0117 ' --temp ' , brain_on_FS_coord_file, ...
0118 ' --o ' , tmp_wm_file, ...
0119 ' --identity'];
0120 dmri_system(cmd, '-echo');
0121
0122
0123
0124 tmp_wm_sum_file = fullfile(work_dir, filesep, 'tmp_wm_sum.nii.gz');
0125 dmri_add_images(tmp_wm_fill_file, ...
0126 tmp_wm_file, ...
0127 tmp_wm_sum_file);
0128
0129
0130 tmp_wm_sum_bin_file = fullfile(work_dir, filesep, 'tmp_wm_sum_bin.nii.gz');
0131 cmd = ['fslmaths', ...
0132 ' ', tmp_wm_sum_file, ...
0133 ' -thr 0 ', ...
0134 ' -bin ' , tmp_wm_sum_bin_file];
0135 dmri_system(cmd);
0136
0137
0138
0139
0140
0141 tmp_wm_sum_bin_on_struct_coord_file = fullfile(work_dir, filesep, 'tmp_wm_sum_bin_on_structcoord.nii.gz');
0142 dmri_image_transform(tmp_wm_sum_bin_file, ...
0143 tmp_wm_sum_bin_on_struct_coord_file, ...
0144 ref_struct_niigz_file, ...
0145 'fs2struct', ...
0146 trans_info_dir);
0147
0148
0149 output_dir = fileparts(output_wm_niigz_file);
0150 if exist(output_dir, 'dir') ~= 7
0151 mkdir(output_dir);
0152 end
0153 dmri_image_transform(tmp_wm_sum_bin_on_struct_coord_file, ...
0154 output_wm_niigz_file, ...
0155 ref_FA_niigz_file, ...
0156 'struct2fa_nointerp', ...
0157 trans_info_dir);
0158 fprintf('White matter volume file created : %s\n', output_wm_niigz_file);
0159
0160
0161 rmdir(work_dir, 's');