add brainmask in align_epi_anat

Hi, afni expert
I am using align_epi_anat and trying to add a weight dataset to adjust the contribution of the cost function. Basically, I have a skullstripped brainmask and want the alignment only consider the cost function that involves brain voxels. I used something like ‘’-Allineate_opts -weight brainmask.nii.gz". See the full command below

align_epi_anat.py -dset1 /home/stone-ext2/primatemri/site-princeton/sub-032114/ses-001/anat/sub-032114_ses-001_run-2_T1w.nii.gz -dset2 /home/stone-ext2/primatemri/site-princeton/sub-032114/ses-001/anat/sub-032114_ses-001_run-1_T1w.nii.gz -master_dset1 /home/stone-ext2/primatemri/site-princeton/sub-032114/ses-001/anat/sub-032114_ses-001_run-1_T1w.nii.gz -suffix _al.nii.gz -dset1to2 -output_dir /home/stone-ext2/primatemri/site-princeton/sub-032114/anatpp -giant_move -dset1_strip None -dset2_strip None -overwrite -rigid_body -Allineate_opts -weight /home/stone-ext2/primatemri/site-princeton/sub-032114/anatpp/sub-032114_ses-001_run-1_T1w_ssmask.nii.gz

However, it seems that align_epi_anat will automatically generate a brainmask and thus the -weight option will be double set. See the last part of the command output. Can I ask how to pass ‘-weight’ to internal 3dAllineate function??

Thanks.

++ 3dbucket: AFNI version=AFNI_18.2.19 (Sep 27 2018) [64-bit] [0/1842]
#++ removing skull or area outside brain
#++ Computing weight mask
#Script is running (command trimmed):
3dBrickStat -automask -percentile 90.000000 1 90.000000 ./__tt_sub-032114_ses-001_run-1_T1w_ts+orig
#++ Applying threshold of 1158.000000 on /home/stone-ext2/primatemri/site-princeton/sub-032114/anatpp/__tt_sub-032114_ses-001_run-1_T1w_ts+orig
#Script is running (command trimmed):
3dcalc -datum float -prefix ./__tt_sub-032114_ses-001_run-1_T1w_ts_wt -a ./__tt_sub-032114_ses-001_run-1_T1w_ts+orig -expr ‘min(1,(a/1158.000000))’
++ 3dcalc: AFNI version=AFNI_18.2.19 (Sep 27 2018) [64-bit]
++ Authored by: A cast of thousands
++ Output dataset ././__tt_sub-032114_ses-001_run-1_T1w_ts_wt+orig.BRIK
#++ Aligning dset1 data to dset2 data
#Script is running (command trimmed):
3dAllineate -lpa -wtprefix ./__tt_sub-032114_ses-001_run-2_T1w_al.nii.gz_wtal -weight ./__tt_sub-032114_ses-001_run-1_T1w_ts_wt+orig -source ./__tt_sub-032114_ses-001_run-2_T1w+orig -prefix ./sub-032114_ses-001_run-2_T1w_al.nii.gz -base ./__tt_sub-032114_ses-001_run-1_T1w_ts+orig -cmass -1Dmatrix_save ./sub-032114_ses-001_run-2_T1w_al.nii.gz_mat.aff12.1D -master /home/stone-ext2/primatemri/site-princeton/sub-032114/ses-001/anat/sub-032114_ses-001_run-1_T1w.nii.gz -weight ./sub-032114_ses-001_run-1_T1w_ssmask.nii.gz -twobest 11 -twopass -VERB -maxrot 45 -maxshf 40 -fineblur 1 -source_automask+2
++ 3dAllineate: AFNI version=AFNI_18.2.19 (Sep 27 2018) [64-bit]
++ Authored by: Zhark the Registrator
** FATAL ERROR: Can’t have multiple -weight options :frowning:
** Program compile date = Sep 27 2018
** 3dAllineate failure
** ERROR - script failed

You can turn off skullstripping for anat and epi datasets in align_epi_anat.py. The weighting for the epi data is applied in any case, and there is no option to turn it off, but that’s not what you are interested in here, I think. The mask for the anatomical dataset is usually computed with 3dSkullstrip. If you turn that off, then all voxels are used. You can turn the skullstripping off with “-dset1_strip None” or “-anat_has_skull no”. If you want to compute alignment for a masked dataset and apply the transformation to another dataset, you can use the “-child_anat” or “-child_epi” options.

Hi, Daniel
Thanks for your reply!. I did try to avoid the skull-stripping step. I cleaned up my cmd a little bit. As you can see, I set ‘-dset1_strp None -dset2_strip None’

align_epi_anat.py -dset1 dset.nii.gz -dset2 dset2.nii.gz -master_dset2 dset2.nii.gz -suffix _al.nii.gz -dset1to2 -output_dir outputdir -giant_move -dset1_strip None -dset2_strip None -overwrite -rigid_body -Allineate_opts -weight dset2_brainmask.nii.gz

But it still internally add a -weight input. Did I miss something?

#Script is running (command trimmed):
3dAllineate -lpa -wtprefix ./__tt_dset2.nii.gz_wtal -weight ./__tt_dset1_ts_wt+orig -source ./__tt_dset2 -prefix ./dset1.nii.gz -base ./__tt_dset2_ts+orig -cmass -1Dmatrix_save ./dset2_al.nii.gz_mat.aff12.1D -master BASE -mast_dxyz 0.500000 -weight ./dset1_brainmask.nii.gz -twobest 11 -twopass -VERB -maxrot 45 -maxshf 40 -fineblur 1
-source_automask+2
++ 3dAllineate: AFNI version=AFNI_18.2.19 (Sep 27 2018) [64-bit]
++ Authored by: Zhark the Registrator
*+ WARNING: Small value 0.5 after -mast_dxyz :frowning:
** FATAL ERROR: Can’t have multiple -weight options :frowning:
** Program compile date = Sep 27 2018
** 3dAllineate failure
** ERROR - script failed

thanks.

ruyuan

I did say align_epi_anat.py applies a weight, and you can’t turn it off with align_epi_anat.py as it is now. You can always use 3dAllineate directly. I’m not clear what it is you are trying to accomplish. Maybe describe that in some more detail, and we can offer a solution.

Hi, Daniel
Thanks for your reply.
I am currently trying to align to macaque T1 images (has skull) so I can average them and improve SNR. I used the align_epi_anat.py.
align_epi_anat.py -dset1 dset1.nii.gz -dset2 dset2.nii.gz -master_dset2 dset2.nii.gz -suffix _al.nii.gz -dset1to2 -overwrite

The alignment was good and gave the dset1to2_mat.aff12.1D. The only problem is that the resulted file is a skull-stripped version and I want to keep the skull in the aligned image. So I planed to use 3dAllineate to directly transform the original image. I first obtained the inverse transformation from align_epi_anat.py
cat_matvec -ONELINE dset1to2_mat.aff12.1D -I > dset1to2_matINV.aff12.1D
I then used 3dAllineate and applied the inverse transformation
3dAllineate -input dset1.nii.gz -1Dparam_apply dset1to2_matINV.aff12.1D -master dset2.nii.gz -prefix dset1_al2.nii.gz -overwrite

However, the result looks completely wrong. It seems that the align_epi_anat.py step is correct but somehow I wrongly used the obtained transformation. Can you provide some insights here?

Thanks so much. I am sorry that I did not clearly describle the problem

ruyuan

1Dparam_apply apply parameters (rotations, translations, etc), not a matrix. Use 1Dmatrix_apply instead.

oops, I see. Thanks for pointing out the mistake.