0001 function command = dmri_image_transform_cmd_get(from_file, to_file, to_ref_file, ...
0002 direction, transinfo_dir)
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 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
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
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
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
0082 command = ['applywarp -i ' from_file, ...
0083 ' -o ', to_file, ...
0084 ' ' , ref_option, ...
0085 ' -w ', struct2fa_file, ...
0086 ' ' , interp_option];
0087 end