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

dmri_wm_FA_volume_create

PURPOSE ^

Create whitematter volume on FA coordinate system.

SYNOPSIS ^

function dmri_wm_FA_volume_create(fs_dir,ref_struct_niigz_file,ref_FA_niigz_file, trans_info_dir,output_wm_niigz_file)

DESCRIPTION ^

 Create whitematter volume on FA coordinate system.
 The whitematter is the one created by FreeSurfer(lh.smoothwm, rh/smoothwm).

 [Usage]
    dmri_wm_FA_volume_create(fs_dir, ...
                             ref_struct_niigz_file, ...
                             ref_FA_niigz_file, trans_info_dir, ...
                             output_wm_niigz_file)

 [Input]
                   fs_dir : Freesurfer subject directory.
    ref_struct_niigz_file : reference struct brain image file (niftigz format).
        ref_FA_niigz_file : reference FA(Fractional anisotrophy) image file (niftigz format).
           trans_info_dir : The directory which cnotains transform infomation files
                            created by dti_transwarp_info_create.m
     output_wm_niigz_file : White matter volume data on FA coordinate system.

 [Output]
    none


 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_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 % Create whitematter volume on FA coordinate system.
0006 % The whitematter is the one created by FreeSurfer(lh.smoothwm, rh/smoothwm).
0007 %
0008 % [Usage]
0009 %    dmri_wm_FA_volume_create(fs_dir, ...
0010 %                             ref_struct_niigz_file, ...
0011 %                             ref_FA_niigz_file, trans_info_dir, ...
0012 %                             output_wm_niigz_file)
0013 %
0014 % [Input]
0015 %                   fs_dir : Freesurfer subject directory.
0016 %    ref_struct_niigz_file : reference struct brain image file (niftigz format).
0017 %        ref_FA_niigz_file : reference FA(Fractional anisotrophy) image file (niftigz format).
0018 %           trans_info_dir : The directory which cnotains transform infomation files
0019 %                            created by dti_transwarp_info_create.m
0020 %     output_wm_niigz_file : White matter volume data on FA coordinate system.
0021 %
0022 % [Output]
0023 %    none
0024 %
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 ~= 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 % --- Main Procedure
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 % Create working directory
0058 work_dir = tempname;
0059 mkdir(work_dir);
0060 
0061 
0062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0063 % read white matter label
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 % Create .label file of White matter
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 % Create white matter volume
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 % Fill inner white matter surface
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 % lh_fill + rh_fill = fill
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 % Convert label to volume(only label)
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, ... % Template. the same size and geometry as the template.
0118        ' --o '    , tmp_wm_file, ... % Single frame output volume.
0119        ' --identity'];
0120 dmri_system(cmd, '-echo');
0121 
0122 % Create whitematter with label
0123 %  tmp_wm_sum.nii.gz  = tmp_wm_fill_file(whitematter) + tmp_wm.nii.gz(label)
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 % Binarize
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 % Convert from FreeSurfer space to FA space
0139 
0140 % Convert from FreeSurfer to Stuct image space
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 % Convert Struct image space to FA space
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 % delete working directory
0161 rmdir(work_dir, 's');

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