%%%%%%%% Add SPM-----------------------------------
spm_path = 'C:\Program Files\spm12';addpath(spm_path)
spm('Defaults', 'fMRI');
spm_jobman('initcfg');
%%%%%%----------------------------------------
%%%%%% DEFINE THE FOLLOWING
%%%%%%---------------------------------------
directory = 'D:\HCP35\unzipped'; %%%%% for HCP35
subfolder = 'anat\T1'; %%%% for HCP35
anatomical_name = 'T1'; %%%%% for HCP35
HT_suffix = '_HT_New';

folder_list = {'mgh_1001',...
'mgh_1002',...
'mgh_1003',...
'mgh_1004',...
'mgh_1005',...
'mgh_1006',...
'mgh_1007',...
'mgh_1008',...
'mgh_1009',...
'mgh_1010',...
'mgh_1011',...
'mgh_1012',...
'mgh_1013',...
'mgh_1014',...
'mgh_1015',...
'mgh_1016',...
'mgh_1017',...
'mgh_1018',...
'mgh_1019',...
'mgh_1021',...
'mgh_1022',...
'mgh_1023',...
'mgh_1024',...
'mgh_1025',...
'mgh_1026',...
'mgh_1027',...
'mgh_1028',...
'mgh_1029',...
'mgh_1030',...
'mgh_1031',...
'mgh_1032',...
'mgh_1033',...
'mgh_1034'};

[~, num] = size(folder_list);
cd(directory);

%%%%% MAKE FS-DTI THALAMIC ROIS

for foldernum = 1:num
    currentfolder = [folder_list{foldernum} '\' subfolder];  

    for b = 1:46
        matlabbatch{b}.spm.util.imcalc.input = {[directory '\' currentfolder '\thal_cnn_outputSegmentation.nii,1']};
        matlabbatch{b}.spm.util.imcalc.outdir = {[directory '\' currentfolder '\']};
        matlabbatch{b}.spm.util.imcalc.var = struct('name', {}, 'value', {});
        matlabbatch{b}.spm.util.imcalc.options.dmtx = 0;
        matlabbatch{b}.spm.util.imcalc.options.mask = 0;
        matlabbatch{b}.spm.util.imcalc.options.interp = 1;
        matlabbatch{b}.spm.util.imcalc.options.dtype = 4;
    end

    matlabbatch{1}.spm.util.imcalc.output = 'AV_L_FS_DTI';
    matlabbatch{1}.spm.util.imcalc.expression = 'i1==8103';

    matlabbatch{2}.spm.util.imcalc.output = 'CeM_L_FS_DTI';
    matlabbatch{2}.spm.util.imcalc.expression = 'i1==8104';

    matlabbatch{3}.spm.util.imcalc.output = 'CL_L_FS_DTI';
    matlabbatch{3}.spm.util.imcalc.expression = 'i1==8105';

    matlabbatch{4}.spm.util.imcalc.output = 'CM_L_FS_DTI';
    matlabbatch{4}.spm.util.imcalc.expression = 'i1==8106';

    matlabbatch{5}.spm.util.imcalc.output = 'LD_L_FS_DTI';
    matlabbatch{5}.spm.util.imcalc.expression = 'i1==8108';

    matlabbatch{6}.spm.util.imcalc.output = 'LGN_L_FS_DTI';
    matlabbatch{6}.spm.util.imcalc.expression = 'i1==8109';

    matlabbatch{7}.spm.util.imcalc.output = 'LP_L_FS_DTI';
    matlabbatch{7}.spm.util.imcalc.expression = 'i1==8110';

    matlabbatch{8}.spm.util.imcalc.output = 'LSg_L_FS_DTI';
    matlabbatch{8}.spm.util.imcalc.expression = 'i1==8111';

    matlabbatch{9}.spm.util.imcalc.output = 'MDl_L_FS_DTI';
    matlabbatch{9}.spm.util.imcalc.expression = 'i1==8112';   

    matlabbatch{10}.spm.util.imcalc.output = 'MDm_L_FS_DTI';
    matlabbatch{10}.spm.util.imcalc.expression = 'i1==8113';  

    matlabbatch{11}.spm.util.imcalc.output = 'MGN_L_FS_DTI';
    matlabbatch{11}.spm.util.imcalc.expression = 'i1==8115';  

    matlabbatch{12}.spm.util.imcalc.output = 'MVRe_L_FS_DTI';
    matlabbatch{12}.spm.util.imcalc.expression = 'i1==8116';

    matlabbatch{13}.spm.util.imcalc.output = 'Pf_L_FS_DTI';
    matlabbatch{13}.spm.util.imcalc.expression = 'i1==8118';

    matlabbatch{14}.spm.util.imcalc.output = 'PuA_L_FS_DTI';
    matlabbatch{14}.spm.util.imcalc.expression = 'i1==8120';

    matlabbatch{15}.spm.util.imcalc.output = 'PuI_L_FS_DTI';
    matlabbatch{15}.spm.util.imcalc.expression = 'i1==8121';

    matlabbatch{16}.spm.util.imcalc.output = 'PuL_L_FS_DTI';
    matlabbatch{16}.spm.util.imcalc.expression = 'i1==8122';

    matlabbatch{17}.spm.util.imcalc.output = 'VA_L_FS_DTI';
    matlabbatch{17}.spm.util.imcalc.expression = 'i1==8126';

    matlabbatch{18}.spm.util.imcalc.output = 'VAmc_L_FS_DTI';
    matlabbatch{18}.spm.util.imcalc.expression = 'i1==8127';

    matlabbatch{19}.spm.util.imcalc.output = 'VLa_L_FS_DTI';
    matlabbatch{19}.spm.util.imcalc.expression = 'i1==8128';

    matlabbatch{20}.spm.util.imcalc.output = 'VLp_L_FS_DTI';
    matlabbatch{20}.spm.util.imcalc.expression = 'i1==8129';

    matlabbatch{21}.spm.util.imcalc.output = 'VPL_L_FS_DTI';
    matlabbatch{21}.spm.util.imcalc.expression = 'i1==8133';

    matlabbatch{22}.spm.util.imcalc.output = 'PuMm_L_FS_DTI';
    matlabbatch{22}.spm.util.imcalc.expression = 'i1==8135';

    matlabbatch{23}.spm.util.imcalc.output = 'PuMl_L_FS_DTI';
    matlabbatch{23}.spm.util.imcalc.expression = 'i1==8136';  

    matlabbatch{24}.spm.util.imcalc.output = 'AV_R_FS_DTI';
    matlabbatch{24}.spm.util.imcalc.expression = 'i1==8203';

    matlabbatch{25}.spm.util.imcalc.output = 'CeM_R_FS_DTI';
    matlabbatch{25}.spm.util.imcalc.expression = 'i1==8204';

    matlabbatch{26}.spm.util.imcalc.output = 'CL_R_FS_DTI';
    matlabbatch{26}.spm.util.imcalc.expression = 'i1==8205';

    matlabbatch{27}.spm.util.imcalc.output = 'CM_R_FS_DTI';
    matlabbatch{27}.spm.util.imcalc.expression = 'i1==8206';

    matlabbatch{28}.spm.util.imcalc.output = 'LD_R_FS_DTI';
    matlabbatch{28}.spm.util.imcalc.expression = 'i1==8208';

    matlabbatch{29}.spm.util.imcalc.output = 'LGN_R_FS_DTI';
    matlabbatch{29}.spm.util.imcalc.expression = 'i1==8209';

    matlabbatch{30}.spm.util.imcalc.output = 'LP_R_FS_DTI';
    matlabbatch{30}.spm.util.imcalc.expression = 'i1==8210';

    matlabbatch{31}.spm.util.imcalc.output = 'LSg_R_FS_DTI';
    matlabbatch{31}.spm.util.imcalc.expression = 'i1==8211';

    matlabbatch{32}.spm.util.imcalc.output = 'MDl_R_FS_DTI';
    matlabbatch{32}.spm.util.imcalc.expression = 'i1==8212';   

    matlabbatch{33}.spm.util.imcalc.output = 'MDm_R_FS_DTI';
    matlabbatch{33}.spm.util.imcalc.expression = 'i1==8213';  

    matlabbatch{34}.spm.util.imcalc.output = 'MGN_R_FS_DTI';
    matlabbatch{34}.spm.util.imcalc.expression = 'i1==8215';  

    matlabbatch{35}.spm.util.imcalc.output = 'MVRe_R_FS_DTI';
    matlabbatch{35}.spm.util.imcalc.expression = 'i1==8216';

    matlabbatch{36}.spm.util.imcalc.output = 'Pf_R_FS_DTI';
    matlabbatch{36}.spm.util.imcalc.expression = 'i1==8218';

    matlabbatch{37}.spm.util.imcalc.output = 'PuA_R_FS_DTI';
    matlabbatch{37}.spm.util.imcalc.expression = 'i1==8220';

    matlabbatch{38}.spm.util.imcalc.output = 'PuI_R_FS_DTI';
    matlabbatch{38}.spm.util.imcalc.expression = 'i1==8221';

    matlabbatch{39}.spm.util.imcalc.output = 'PuL_R_FS_DTI';
    matlabbatch{39}.spm.util.imcalc.expression = 'i1==8222';

    matlabbatch{40}.spm.util.imcalc.output = 'VA_R_FS_DTI';
    matlabbatch{40}.spm.util.imcalc.expression = 'i1==8226';

    matlabbatch{41}.spm.util.imcalc.output = 'VAmc_R_FS_DTI';
    matlabbatch{41}.spm.util.imcalc.expression = 'i1==8227';

    matlabbatch{42}.spm.util.imcalc.output = 'VLa_R_FS_DTI';
    matlabbatch{42}.spm.util.imcalc.expression = 'i1==8228';

    matlabbatch{43}.spm.util.imcalc.output = 'VLp_R_FS_DTI';
    matlabbatch{43}.spm.util.imcalc.expression = 'i1==8229';

    matlabbatch{44}.spm.util.imcalc.output = 'VPL_R_FS_DTI';
    matlabbatch{44}.spm.util.imcalc.expression = 'i1==8233';

    matlabbatch{45}.spm.util.imcalc.output = 'PuMm_R_FS_DTI';
    matlabbatch{45}.spm.util.imcalc.expression = 'i1==8235';

    matlabbatch{46}.spm.util.imcalc.output = 'PuMl_R_FS_DTI';
    matlabbatch{46}.spm.util.imcalc.expression = 'i1==8236';

spm_jobman('run',matlabbatch) % run it
cd(directory) % move back from that participant's folder to the folder containing all
end
% % % % % --------------------------------------------------------------------------------
% % % % % % MAKE FS-T1 ROIS
% % % % % ----------------------------
for foldernum = 1:num

    currentfolder = [folder_list{foldernum} '\' subfolder];  

    for b = 1:44
        matlabbatch{b}.spm.util.imcalc.input = {[currentfolder '\ThalamicNuclei.FSvoxelSpace-in-rawavg.nii,1']};
        matlabbatch{b}.spm.util.imcalc.outdir = {[currentfolder '\']};
        matlabbatch{b}.spm.util.imcalc.var = struct('name', {}, 'value', {});
        matlabbatch{b}.spm.util.imcalc.options.dmtx = 0;
        matlabbatch{b}.spm.util.imcalc.options.mask = 0;
        matlabbatch{b}.spm.util.imcalc.options.interp = 1;
        matlabbatch{b}.spm.util.imcalc.options.dtype = 4;
    end

    matlabbatch{1}.spm.util.imcalc.output = 'AV_L_FS_T1';
    matlabbatch{1}.spm.util.imcalc.expression = 'i1==8103';

    matlabbatch{2}.spm.util.imcalc.output = 'CeM_L_FS_T1';
    matlabbatch{2}.spm.util.imcalc.expression = 'i1==8104';

    matlabbatch{3}.spm.util.imcalc.output = 'CL_L_FS_T1';
    matlabbatch{3}.spm.util.imcalc.expression = 'i1==8105';

    matlabbatch{4}.spm.util.imcalc.output = 'CM_L_FS_T1';
    matlabbatch{4}.spm.util.imcalc.expression = 'i1==8106';

    matlabbatch{5}.spm.util.imcalc.output = 'LD_L_FS_T1';
    matlabbatch{5}.spm.util.imcalc.expression = 'i1==8108';

    matlabbatch{6}.spm.util.imcalc.output = 'LGN_L_FS_T1';
    matlabbatch{6}.spm.util.imcalc.expression = 'i1==8109';

    matlabbatch{7}.spm.util.imcalc.output = 'LP_L_FS_T1';
    matlabbatch{7}.spm.util.imcalc.expression = 'i1==8110';

    matlabbatch{8}.spm.util.imcalc.output = 'LSg_L_FS_T1';
    matlabbatch{8}.spm.util.imcalc.expression = 'i1==8111';

    matlabbatch{9}.spm.util.imcalc.output = 'MDl_L_FS_T1';
    matlabbatch{9}.spm.util.imcalc.expression = 'i1==8112';   

    matlabbatch{10}.spm.util.imcalc.output = 'MDm_L_FS_T1';
    matlabbatch{10}.spm.util.imcalc.expression = 'i1==8113';  

    matlabbatch{11}.spm.util.imcalc.output = 'MGN_L_FS_T1';
    matlabbatch{11}.spm.util.imcalc.expression = 'i1==8115';  

    matlabbatch{12}.spm.util.imcalc.output = 'MVRe_L_FS_T1';
    matlabbatch{12}.spm.util.imcalc.expression = 'i1==8116';

    matlabbatch{13}.spm.util.imcalc.output = 'Pf_L_FS_T1';
    matlabbatch{13}.spm.util.imcalc.expression = 'i1==8118';

    matlabbatch{14}.spm.util.imcalc.output = 'PuA_L_FS_T1';
    matlabbatch{14}.spm.util.imcalc.expression = 'i1==8120';

    matlabbatch{15}.spm.util.imcalc.output = 'PuI_L_FS_T1';
    matlabbatch{15}.spm.util.imcalc.expression = 'i1==8121';

    matlabbatch{16}.spm.util.imcalc.output = 'PuL_L_FS_T1';
    matlabbatch{16}.spm.util.imcalc.expression = 'i1==8122';

    matlabbatch{17}.spm.util.imcalc.output = 'VA_L_FS_T1';
    matlabbatch{17}.spm.util.imcalc.expression = 'i1==8126';

    matlabbatch{18}.spm.util.imcalc.output = 'VAmc_L_FS_T1';
    matlabbatch{18}.spm.util.imcalc.expression = 'i1==8127';

    matlabbatch{19}.spm.util.imcalc.output = 'VLa_L_FS_T1';
    matlabbatch{19}.spm.util.imcalc.expression = 'i1==8128';

    matlabbatch{20}.spm.util.imcalc.output = 'VLp_L_FS_T1';
    matlabbatch{20}.spm.util.imcalc.expression = 'i1==8129';

    matlabbatch{21}.spm.util.imcalc.output = 'VPL_L_FS_T1';
    matlabbatch{21}.spm.util.imcalc.expression = 'i1==8133';
%%%%%note, different from FS-DTI!!!
    matlabbatch{22}.spm.util.imcalc.output = 'PuM_L_FS_T1';
    matlabbatch{22}.spm.util.imcalc.expression = 'i1==8123';  

    matlabbatch{23}.spm.util.imcalc.output = 'AV_R_FS_T1';
    matlabbatch{23}.spm.util.imcalc.expression = 'i1==8203';

    matlabbatch{24}.spm.util.imcalc.output = 'CeM_R_FS_T1';
    matlabbatch{24}.spm.util.imcalc.expression = 'i1==8204';

    matlabbatch{25}.spm.util.imcalc.output = 'CL_R_FS_T1';
    matlabbatch{25}.spm.util.imcalc.expression = 'i1==8205';

    matlabbatch{26}.spm.util.imcalc.output = 'CM_R_FS_T1';
    matlabbatch{26}.spm.util.imcalc.expression = 'i1==8206';

    matlabbatch{27}.spm.util.imcalc.output = 'LD_R_FS_T1';
    matlabbatch{27}.spm.util.imcalc.expression = 'i1==8208';

    matlabbatch{28}.spm.util.imcalc.output = 'LGN_R_FS_T1';
    matlabbatch{28}.spm.util.imcalc.expression = 'i1==8209';

    matlabbatch{29}.spm.util.imcalc.output = 'LP_R_FS_T1';
    matlabbatch{29}.spm.util.imcalc.expression = 'i1==8210';

    matlabbatch{30}.spm.util.imcalc.output = 'LSg_R_FS_T1';
    matlabbatch{30}.spm.util.imcalc.expression = 'i1==8211';

    matlabbatch{31}.spm.util.imcalc.output = 'MDl_R_FS_T1';
    matlabbatch{31}.spm.util.imcalc.expression = 'i1==8212';   

    matlabbatch{32}.spm.util.imcalc.output = 'MDm_R_FS_T1';
    matlabbatch{32}.spm.util.imcalc.expression = 'i1==8213';  

    matlabbatch{33}.spm.util.imcalc.output = 'MGN_R_FS_T1';
    matlabbatch{33}.spm.util.imcalc.expression = 'i1==8215';  

    matlabbatch{34}.spm.util.imcalc.output = 'MVRe_R_FS_T1';
    matlabbatch{34}.spm.util.imcalc.expression = 'i1==8216';

    matlabbatch{35}.spm.util.imcalc.output = 'Pf_R_FS_T1';
    matlabbatch{35}.spm.util.imcalc.expression = 'i1==8218';

    matlabbatch{36}.spm.util.imcalc.output = 'PuA_R_FS_T1';
    matlabbatch{36}.spm.util.imcalc.expression = 'i1==8220';

    matlabbatch{37}.spm.util.imcalc.output = 'PuI_R_FS_T1';
    matlabbatch{37}.spm.util.imcalc.expression = 'i1==8221';

    matlabbatch{38}.spm.util.imcalc.output = 'PuL_R_FS_T1';
    matlabbatch{38}.spm.util.imcalc.expression = 'i1==8222';

    matlabbatch{39}.spm.util.imcalc.output = 'VA_R_FS_T1';
    matlabbatch{39}.spm.util.imcalc.expression = 'i1==8226';

    matlabbatch{40}.spm.util.imcalc.output = 'VAmc_R_FS_T1';
    matlabbatch{40}.spm.util.imcalc.expression = 'i1==8227';

    matlabbatch{41}.spm.util.imcalc.output = 'VLa_R_FS_T1';
    matlabbatch{41}.spm.util.imcalc.expression = 'i1==8228';

    matlabbatch{42}.spm.util.imcalc.output = 'VLp_R_FS_T1';
    matlabbatch{42}.spm.util.imcalc.expression = 'i1==8229';

    matlabbatch{43}.spm.util.imcalc.output = 'VPL_R_FS_T1';
    matlabbatch{43}.spm.util.imcalc.expression = 'i1==8233';
%%%%%note, different from FS-DTI!

    matlabbatch{44}.spm.util.imcalc.output = 'PuM_R_FS_T1';
    matlabbatch{44}.spm.util.imcalc.expression = 'i1==8223';


%%%%%%%% Run the job
spm_jobman('run', matlabbatch);
% %%%%%%%for loop
end

%%%MAKE HIPS-THOMAS ROIS

for foldernum = 1:num
    currentfolder = [folder_list{foldernum} '\' subfolder];    
    %-----------------------------------------------------------------
    fprintf('unzipping, moving, coregistering with anatomical, and renaming HIPS-THOMAS segmentations for %s\n', folder_list{foldernum});
    % unzip the masks
    gunzip([directory '\' currentfolder '\left\2-AV.nii.gz']);
    gunzip([directory '\' currentfolder '\left\4-VA.nii.gz']);
    gunzip([directory '\' currentfolder '\left\5-VLa.nii.gz']);
    gunzip([directory '\' currentfolder '\left\6_VLPd.nii.gz']);
    gunzip([directory '\' currentfolder '\left\6_VLPv.nii.gz']);
    gunzip([directory '\' currentfolder '\left\6-VLP.nii.gz']);
    gunzip([directory '\' currentfolder '\left\7-VPL.nii.gz']);
    gunzip([directory '\' currentfolder '\left\8-Pul.nii.gz']);
    gunzip([directory '\' currentfolder '\left\9-LGN.nii.gz']);
    gunzip([directory '\' currentfolder '\left\10-MGN.nii.gz']);
    gunzip([directory '\' currentfolder '\left\11-CM.nii.gz']);
    gunzip([directory '\' currentfolder '\left\12-MD-Pf.nii.gz']);
    gunzip([directory '\' currentfolder '\left\4567-VL.nii.gz']);
    gunzip([directory '\' currentfolder '\left\CL_L.nii.gz']); % from new HT
    gunzip([directory '\' currentfolder '\left\ocrop_T1.nii.gz']);

    gunzip([directory '\' currentfolder '\right\2-AV.nii.gz']);
    gunzip([directory '\' currentfolder '\right\4-VA.nii.gz']);
    gunzip([directory '\' currentfolder '\right\5-VLa.nii.gz']);
    gunzip([directory '\' currentfolder '\right\6_VLPd.nii.gz']);
    gunzip([directory '\' currentfolder '\right\6_VLPv.nii.gz']);
    gunzip([directory '\' currentfolder '\right\6-VLP.nii.gz']);
    gunzip([directory '\' currentfolder '\right\7-VPL.nii.gz']);
    gunzip([directory '\' currentfolder '\right\8-Pul.nii.gz']);
    gunzip([directory '\' currentfolder '\right\9-LGN.nii.gz']);
    gunzip([directory '\' currentfolder '\right\10-MGN.nii.gz']);
    gunzip([directory '\' currentfolder '\right\11-CM.nii.gz']);
    gunzip([directory '\' currentfolder '\right\12-MD-Pf.nii.gz']);
    gunzip([directory '\' currentfolder '\right\4567-VL.nii.gz']);
    gunzip([directory '\' currentfolder '\right\CL_R.nii.gz']); % from new HT
    gunzip([directory '\' currentfolder '\right\ocrop_T1.nii.gz']);

    %%%------------------------------------------------------------------
    %%% coregister unzipped  to crestore in native masks, along
    %%% with all HIPS-THOMAS masks, left and right
    matlabbatch{1}.spm.spatial.coreg.estimate.ref = {[directory '\' currentfolder '\' anatomical_name '.nii,1']};
    matlabbatch{1}.spm.spatial.coreg.estimate.source = {[directory '\' currentfolder '\left\ocrop_T1.nii,1']};

    matlabbatch{1}.spm.spatial.coreg.estimate.other = {
        [directory '\' currentfolder '\left\2-AV.nii,1']
        [directory '\' currentfolder '\left\4-VA.nii,1']
        [directory '\' currentfolder '\left\5-VLa.nii,1']
        [directory '\' currentfolder '\left\6_VLPd.nii,1']
        [directory '\' currentfolder '\left\6_VLPv.nii,1']
        [directory '\' currentfolder '\left\6-VLP.nii,1']
        [directory '\' currentfolder '\left\7-VPL.nii,1']
        [directory '\' currentfolder '\left\8-Pul.nii,1']
        [directory '\' currentfolder '\left\9-LGN.nii,1']
        [directory '\' currentfolder '\left\10-MGN.nii,1']
        [directory '\' currentfolder '\left\11-CM.nii,1']
        [directory '\' currentfolder '\left\12-MD-Pf.nii,1']
        [directory '\' currentfolder '\left\4567-VL.nii,1']
    };
    matlabbatch{2}.spm.spatial.coreg.estimate.ref = {[directory '\' currentfolder '\' anatomical_name '.nii,1']};
    % matlabbatch{2}.spm.spatial.coreg.estimate.source = {[directory '\' currentfolder '\right\ocrop_crestore.nii,1']};
        matlabbatch{2}.spm.spatial.coreg.estimate.source = {[directory '\' currentfolder '\right\ocrop_T1.nii,1']};

    matlabbatch{2}.spm.spatial.coreg.estimate.other = {
        [directory '\' currentfolder '\right\2-AV.nii,1']
        [directory '\' currentfolder '\right\4-VA.nii,1']
        [directory '\' currentfolder '\right\5-VLa.nii,1']
        [directory '\' currentfolder '\right\6_VLPd.nii,1']
        [directory '\' currentfolder '\right\6_VLPv.nii,1']
        [directory '\' currentfolder '\right\6-VLP.nii,1']
        [directory '\' currentfolder '\right\7-VPL.nii,1']
        [directory '\' currentfolder '\right\8-Pul.nii,1']
        [directory '\' currentfolder '\right\9-LGN.nii,1']
        [directory '\' currentfolder '\right\10-MGN.nii,1']
        [directory '\' currentfolder '\right\11-CM.nii,1']
        [directory '\' currentfolder '\right\12-MD-Pf.nii,1']
        [directory '\' currentfolder '\right\4567-VL.nii,1']
                                                       };
    matlabbatch{1}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
    matlabbatch{1}.spm.spatial.coreg.estimate.eoptions.sep = [1 0.5];
    matlabbatch{1}.spm.spatial.coreg.estimate.eoptions.tol = [0.01 0.01 0.01 0.0005 0.0005 0.0005 0.005 0.005 0.005 0.0005 0.0005 0.0005];
    matlabbatch{1}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];

    matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
    matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.sep = [1 0.5];
    matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.tol = [0.01 0.01 0.01 0.0005 0.0005 0.0005 0.005 0.005 0.005 0.0005 0.0005 0.0005];
    matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];


    spm_jobman('run', matlabbatch);
    % % % % % % %------------------------------------------------------------------
    % % % % % % % % move the HIPS-THOMAS masks and rename
    movefile([directory '\' currentfolder '\left\2-AV.nii'], [directory '\' currentfolder '\AV_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\4-VA.nii'], [directory '\' currentfolder '\VA_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\5-VLa.nii'], [directory '\' currentfolder '\VLa_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\6_VLPd.nii'], [directory '\' currentfolder '\VLPd_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\6_VLPv.nii'], [directory '\' currentfolder '\VLPv_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\6-VLP.nii'], [directory '\' currentfolder '\VLP_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\7-VPL.nii'], [directory '\' currentfolder '\VPL_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\8-Pul.nii'], [directory '\' currentfolder '\Pul_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\9-LGN.nii'], [directory '\' currentfolder '\LGN_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\10-MGN.nii'], [directory '\' currentfolder '\MGN_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\11-CM.nii'], [directory '\' currentfolder '\CM_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\12-MD-Pf.nii'], [directory '\' currentfolder '\MD_Pf_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\4567-VL.nii'], [directory '\' currentfolder '\VL_L' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\left\CL_L.nii'], [directory '\' currentfolder '\CL_L' HT_suffix '.nii']); % for new ht

    movefile([directory '\' currentfolder '\right\2-AV.nii'], [directory '\' currentfolder '\AV_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\4-VA.nii'], [directory '\' currentfolder '\VA_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\5-VLa.nii'], [directory '\' currentfolder '\VLa_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\6_VLPd.nii'], [directory '\' currentfolder '\VLPd_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\6_VLPv.nii'], [directory '\' currentfolder '\VLPv_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\6-VLP.nii'], [directory '\' currentfolder '\VLP_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\7-VPL.nii'], [directory '\' currentfolder '\VPL_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\8-Pul.nii'], [directory '\' currentfolder '\Pul_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\9-LGN.nii'], [directory '\' currentfolder '\LGN_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\10-MGN.nii'], [directory '\' currentfolder '\MGN_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\11-CM.nii'], [directory '\' currentfolder '\CM_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\12-MD-Pf.nii'], [directory '\' currentfolder '\MD_Pf_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\4567-VL.nii'], [directory '\' currentfolder '\VL_R' HT_suffix '.nii']);
    movefile([directory '\' currentfolder '\right\CL_R.nii'], [directory '\' currentfolder '\CL_R' HT_suffix '.nii']); % for new ht
end