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

dmri_fodf_calc

PURPOSE ^

Calculate fiber orientation density function.

SYNOPSIS ^

function dmri_fodf_calc(data_niftigz_file, bval_file, bvec_file,area_niftigz_file,mask_niftigz_file,output_mif_file)

DESCRIPTION ^

 Calculate fiber orientation density function.

 [Usage]
    dmri_fodf_calc(data_niftigz_file, bval_file, bvec_file,...
                   area_niftigz_file, ...
                   mask_niftigz_file, ...
                   output_mif_file);

 [Input]
    data_niftigz_file : gzipped Nifti file(.nii.gz)
                        4D series of data volumes.
            bval_file : A text file containing a list of b values applied 
                      during each volume acquisition. The order of entries 
                      in this file must match the order of volumes in 
                      the input data and entries in the gradient 
                       directions text file. 
           bvec_file  : A text file containing a list of gradient directions 
                      applied during diffusion weighted volumes. The order 
                      of entries in this file must match the order of volumes 
                      in the input data series. 
    area_niftigz_file : brain area file(.nii.gz) for response function
                        estimation made by dti_response_estimation_prepare.m
    mask_niftigz_file : struct brain mask image file(.nii.gz) on FA coordinate system.
      output_mif_file : Fiber orientation density function file(.mif)

 [Output]
    none

 [Output files]
     output_mif_file
     response.txt
     gradients-x.txt 

 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_fodf_calc(data_niftigz_file, bval_file, bvec_file, ...
0002                         area_niftigz_file, ...
0003                         mask_niftigz_file, ...
0004                         output_mif_file)
0005 % Calculate fiber orientation density function.
0006 %
0007 % [Usage]
0008 %    dmri_fodf_calc(data_niftigz_file, bval_file, bvec_file,...
0009 %                   area_niftigz_file, ...
0010 %                   mask_niftigz_file, ...
0011 %                   output_mif_file);
0012 %
0013 % [Input]
0014 %    data_niftigz_file : gzipped Nifti file(.nii.gz)
0015 %                        4D series of data volumes.
0016 %            bval_file : A text file containing a list of b values applied
0017 %                      during each volume acquisition. The order of entries
0018 %                      in this file must match the order of volumes in
0019 %                      the input data and entries in the gradient
0020 %                       directions text file.
0021 %           bvec_file  : A text file containing a list of gradient directions
0022 %                      applied during diffusion weighted volumes. The order
0023 %                      of entries in this file must match the order of volumes
0024 %                      in the input data series.
0025 %    area_niftigz_file : brain area file(.nii.gz) for response function
0026 %                        estimation made by dti_response_estimation_prepare.m
0027 %    mask_niftigz_file : struct brain mask image file(.nii.gz) on FA coordinate system.
0028 %      output_mif_file : Fiber orientation density function file(.mif)
0029 %
0030 % [Output]
0031 %    none
0032 %
0033 % [Output files]
0034 %     output_mif_file
0035 %     response.txt
0036 %     gradients-x.txt
0037 %
0038 % Copyright (C) 2011, ATR All Rights Reserved.
0039 % License : New BSD License(see VBMEG_LICENSE.txt)
0040 
0041 %
0042 % --- Previous check
0043 %
0044 if nargin ~= 6
0045     error('Please check input arguments.');
0046 end
0047 if exist(data_niftigz_file, 'file') ~= 2
0048     error('Specified diffusion weighted data file not found.');
0049 end
0050 if exist(area_niftigz_file, 'file') ~= 2
0051     error('Specified brain area file not found.');
0052 end
0053 if exist(mask_niftigz_file, 'file') ~= 2
0054     error('Specified brain mask file not found.');
0055 end
0056 if exist(bval_file, 'file') ~= 2
0057     error('Specified bval_file not found.');
0058 end
0059 if exist(bvec_file, 'file') ~= 2
0060     error('Specified bvec_file not found.');
0061 end
0062 if isempty(output_mif_file)
0063     error('Output filename is empty.');
0064 end
0065 
0066 
0067 %
0068 % --- Main Procedure
0069 %
0070 if exist(output_mif_file, 'file') == 2
0071     copyfile(output_mif_file, [output_mif_file, '.bak'], 'f');
0072     delete(output_mif_file);
0073 end
0074 
0075 output_dir = fileparts(output_mif_file);
0076 work_dir = tempname;
0077 mkdir(work_dir);
0078 
0079 % data copy and unzip
0080 copyfile(data_niftigz_file, work_dir);
0081 copyfile(area_niftigz_file, work_dir);
0082 copyfile(mask_niftigz_file, work_dir);
0083 system(['gunzip ', fullfile(work_dir, filesep, '*.nii.gz')]);
0084 
0085 % create unzipped filename
0086 [p, f, e] = fileparts(data_niftigz_file);
0087 temp_data_nifti_file       = fullfile(work_dir, filesep, strrep([f, e], 'nii.gz', 'nii'));
0088 [p, f, e] = fileparts(area_niftigz_file);
0089 temp_area_nifti_file       = fullfile(work_dir, filesep, strrep([f, e], 'nii.gz', 'nii'));
0090 [p, f, e] = fileparts(mask_niftigz_file);
0091 temp_mask_nifti_file       = fullfile(work_dir, filesep, strrep([f, e], 'nii.gz', 'nii'));
0092 
0093 temp_response_file         = fullfile(work_dir, filesep, 'response.txt');
0094 temp_bvecbval_mrtrix_file  = fullfile(work_dir, filesep, 'gradients-x.txt');
0095 
0096 % Convert format from bvecs, bval => gradients-x.txt
0097 convert_bval_format_to_mrtrix(bval_file, bvec_file, temp_bvecbval_mrtrix_file);
0098 
0099 % Estimate response
0100 cmd = ['estimate_response', ...
0101        ' '      , temp_data_nifti_file, ...
0102        ' -grad ', temp_bvecbval_mrtrix_file, ...
0103        ' '      , temp_area_nifti_file, ...
0104        ' -lmax 6', ...
0105        ' ', temp_response_file];
0106 dmri_system(cmd, '-echo');
0107 
0108 % csdeconv
0109 cmd = ['csdeconv', ...
0110        ' '      , temp_data_nifti_file, ...
0111        ' -grad ', temp_bvecbval_mrtrix_file, ...
0112        ' '      , temp_response_file, ...
0113        ' -lmax 6', ...
0114        ' -mask ', temp_mask_nifti_file, ...
0115        ' ', output_mif_file];
0116 [status, result] = dmri_system(cmd, '-echo');
0117 if status ~= 0
0118     error(result);
0119 end
0120 
0121 % clean up
0122 copyfile(temp_response_file,        output_dir);
0123 copyfile(temp_bvecbval_mrtrix_file, output_dir);
0124 rmdir(work_dir, 's');
0125 
0126 
0127 function [isok] = convert_bval_format_to_mrtrix(bval_file, bvecs_file, bvecbval_mrtrix_file)
0128 
0129 rotbvecs = load(bvecs_file, '-ascii');
0130 rotbvecs = rotbvecs';
0131 
0132 % flip x-axis
0133 rotbvecs(:, 1) = -1 * rotbvecs(:, 1);
0134 
0135 % read bvals
0136 bvals = load(bval_file, '-ascii');
0137 
0138 bb = [rotbvecs, bvals'];
0139 saveascii(bb, bvecbval_mrtrix_file, 8);

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