%This script flirts the files

tic
clear;clc;

cd /home/subhadip/Autism_AnatNet/austistic_study/Anatomy/With_Skull/T1_volumes/D

target_files=dir('t1*.nii.gz');



h=waitbar(0, 'Step 1E')
for l=1:length(target_files)
    setenv('FSLOUTPUTTYPE','NIFTI');
    [status currdir] = system(['flirt -cost normmi -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -interp nearestneighbour -dof 12 -in  MNI152_T1_2mm.nii.gz  -ref  ' target_files(l).name ' -omat chk.mat -out ' target_files(l).name ])
 
    transformation_matrix=load('chk.mat', '-ascii');
%     ch_label=strrep(target_files(l).name, 'brain.nii', 'aff_matrix');
   ch_label=num2str(l,'%03d');
   new=strcat(ch_label,'.mat');
  save(new, 'transformation_matrix','-ascii');
%   new=strcat(ch_label,'.txt');
%   save(new, 'transformation_matrix','-ascii');
  
  [status currdir] = system([' rm ' 'chk.mat' ]);
    
    waitbar(l/length(target_files))  
end
close(h) 

toc