0001 function dmri_response_estimation_prepare(fa_niftigz_file, output_niftigz_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if nargin ~= 2
0021 error('Please check input arguments.');
0022 end
0023 if exist(fa_niftigz_file, 'file') ~= 2
0024 error('Specified FA image not found.');
0025 end
0026
0027
0028
0029
0030 work_dir = tempname;
0031 mkdir(work_dir);
0032 [p, f, e] = fileparts(fa_niftigz_file);
0033
0034
0035 fa_file = fullfile(work_dir, filesep, [f, e]);
0036 copyfile(fa_niftigz_file, fa_file);
0037
0038
0039 tmp2_file = fullfile(work_dir, filesep, 'tmp2.nii.gz');
0040 cmd = ['fslmaths' ...
0041 ' ', fa_file, ...
0042 ' -thr 0.7', ...
0043 ' -bin ', tmp2_file];
0044 dmri_system(cmd);
0045
0046
0047 tmp3_file = fullfile(work_dir, filesep, 'tmp3.nii.gz');
0048 cmd = ['cluster', ...
0049 ' -i ', tmp2_file, ...
0050 ' -t 1',...
0051 ' -o ', tmp3_file];
0052 dmri_system(cmd);
0053
0054
0055 tmp4_file = fullfile(work_dir, filesep, 'max_cluster_val');
0056 cmd = ['fslstats', ...
0057 ' ', tmp3_file, ...
0058 ' -R | cut -d '' '' -f 2 > ', tmp4_file];
0059 dmri_system(cmd);
0060 cmd = ['cat ', tmp4_file];
0061 [s, value_str] = system(cmd);
0062 value_str = strrep(value_str, sprintf('\n'), '');
0063
0064
0065 output_dir = fileparts(output_niftigz_file);
0066 if exist(output_dir, 'dir') ~= 7
0067 mkdir(output_dir);
0068 end
0069 cmd = ['fslmaths', ...
0070 ' ', tmp3_file, ...
0071 ' -thr ', value_str, ...
0072 ' -uthr ' value_str, ...
0073 ' -bin ' output_niftigz_file];
0074 dmri_system(cmd);
0075
0076
0077 copyfile(tmp4_file, output_dir);
0078
0079
0080 rmdir(work_dir, 's');