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

dmri_image_transform_cmd_get

PURPOSE ^

Get command for transform coordinate system.

SYNOPSIS ^

function command = dmri_image_transform_cmd_get(from_file, to_file, to_ref_file,direction, transinfo_dir)

DESCRIPTION ^

 Get command for transform coordinate system.

 [Usage]
    command = dmri_image_transform_cmd_get(from_file, to_file, to_ref_file, ...
                                           direction, transinfo_dir);

 [Input]
        from_file : original niftigz file.
          to_file : transformed and newly create niftigz file.
      to_ref_file : reference image file of to_file.
        direction : transform direction   [string]
                    'fs2struct'          : from freesurfer coord to T1 coord.
                    'struct2fa'          : from T1 coord to FA coord.
                    'struct2fa_nointerp' : from T1 coord to FA coord with no interpolation.
    transinfo_dir : The directory which is including transform files.
                    This directory is made by dti_transwarp_info_create.m

 [Output]
    command : linux command of transform. give it to system function,
              transform will be executed.

 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 command = dmri_image_transform_cmd_get(from_file, to_file, to_ref_file, ...
0002                                                 direction, transinfo_dir)
0003 % Get command for transform coordinate system.
0004 %
0005 % [Usage]
0006 %    command = dmri_image_transform_cmd_get(from_file, to_file, to_ref_file, ...
0007 %                                           direction, transinfo_dir);
0008 %
0009 % [Input]
0010 %        from_file : original niftigz file.
0011 %          to_file : transformed and newly create niftigz file.
0012 %      to_ref_file : reference image file of to_file.
0013 %        direction : transform direction   [string]
0014 %                    'fs2struct'          : from freesurfer coord to T1 coord.
0015 %                    'struct2fa'          : from T1 coord to FA coord.
0016 %                    'struct2fa_nointerp' : from T1 coord to FA coord with no interpolation.
0017 %    transinfo_dir : The directory which is including transform files.
0018 %                    This directory is made by dti_transwarp_info_create.m
0019 %
0020 % [Output]
0021 %    command : linux command of transform. give it to system function,
0022 %              transform will be executed.
0023 %
0024 % Copyright (C) 2011, ATR All Rights Reserved.
0025 % License : New BSD License(see VBMEG_LICENSE.txt)
0026 
0027 %
0028 % --- Previous check
0029 %
0030 if nargin ~= 5
0031     error('Please check input arguments.');
0032 end
0033 if exist(transinfo_dir, 'dir') ~= 7
0034     error(sprintf('transinfo_dir : %s not found.', transinfo_dir));
0035 end
0036 
0037 %
0038 % --- Main Procedure
0039 %
0040 switch(direction)
0041     case 'fs2struct'
0042         ref_option = '';
0043         if ~isempty(to_ref_file)
0044             if exist(to_ref_file, 'file') == 2
0045                 ref_option = ['-ref ', to_ref_file];
0046             else
0047                 warning(sprintf('reference file : %s not found.', to_ref_file));
0048             end
0049         end
0050 
0051         fs2fa_file = fullfile(transinfo_dir, filesep, 'freesurfer2struct.mat');
0052         if exist(fs2fa_file, 'file') ~= 2
0053             error(sprintf('Transform file %s not found.', fs2fa_file));
0054         end
0055         
0056         command = ['flirt -in ' from_file ' ' ref_option, ...
0057                    ' -out ', to_file, ...
0058                    ' -applyxfm -init ' fs2fa_file, ' -interp nearestneighbour'];
0059     case {'struct2fa', 'struct2fa_nointerp'}
0060         ref_option = '';
0061         interp_option = '';
0062         if strcmpi(direction, 'struct2fa_nointerp')
0063             interp_option = '--interp=nn';
0064         end
0065 
0066         % reference check
0067         if ~isempty(to_ref_file)
0068             if exist(to_ref_file, 'file') == 2
0069                 ref_option = ['-r ', to_ref_file];
0070             else
0071                 warning(sprintf('reference file : %s not found.', to_ref_file));
0072             end
0073         end
0074 
0075         % transform file check
0076         struct2fa_file = fullfile(transinfo_dir, filesep, 'struct2fa_warp.nii.gz');
0077         if exist(struct2fa_file, 'file') ~= 2
0078             error(sprintf('Transform file %s not found.', struct2fa_file));
0079         end
0080 
0081         % transform command
0082         command = ['applywarp -i ' from_file, ...
0083                    ' -o ', to_file, ...
0084                    ' '   , ref_option, ...
0085                    ' -w ', struct2fa_file, ...
0086                    ' '   , interp_option];
0087 end

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