@animal_warper can not align atlar D99 Atlas

Hi Everyone,
I am new using afni and the all the suit. To the point, I have several NHP MRIs but in particular I am interesting to do reconstruction of recording sites by electrophysiology. I applied the @animal_warper to the example_subject no problem everything was ok, when I applied to my MRIs was totally distorted (I tested with 2 MRI). Check with detail I figured out that the order (sagittal, coronal, axial ) are uncorrected in my mri, I corrected using 3drefit -orient, I run again but still distorted then I figured out the distortion start at this level
Matrix, aff xform : T1_shft_al2std_mat.aff12.1D
Input, aff-xformed to base (orig res) : T1_shft_al2std.nii.gz
I attach the figure afni display
Any help I will appreciate.
Fabian

Hi, Fabian-

Just to check: were your macaque datasets acquired in sphinx position, and were they entered that way into the program?

Could you please post an image of your initial datasets, similar to what you have done here, but before running @animal_warper?

Also, second check: what version of AFNI do you have on your computer? That is, what is the output of:


afni -ver

–pt

Hi Taylor,
Yes, the monkeys are in sphinx position and I figured out when I checked them by using afni:
I attach the afni display for the T1.nii.gz
First row, it is the original structural MRI
Second row after applying 3drefit -orient RIP T1.nii.gz
and I applied for both the @animal_warper I have the same distortion and unsuccessful in the template overlay
output afni -version : Precompiled binary linux_ubuntu_16_64: Aug 21 2020 (Version AFNI_20.2.14 ‘Aulus Vitellius’)
Any thoughts I will appreciate
Thanks
Fabian

Hi, Fabian-

So, just to be clear, you converted the dataset to show the brain in non-sphinx position (and hopefully left and right are still correct? That is the tricky one to verify…). Then you put this new dataset – with a “standard” positioning, at least from a human brain perspective – into @animal_warper and the warp was still weird? If that is the case, then a few things:

Could you please post your @animal_warper command that you are using? Having these details is useful (esp. to know what template you are using).

To know a bit more about this dataset, in particular if there is any obliquity could you please post the output of this command:


3dWarp   -deoblique   -disp_obl_xform_only  T1.nii.gz 

There is a lot of outside-brain data in your scan; that might confuse the alignment. We can try adjusting for that (e.g., removing all the stuff way below the dataset). But first, I woud like to know what the relative alignment of your dataset at the start is to the template. Can you run this script, where you substitute the name of your “T1.nii.gz” where INPUT_DATASET is, and the name of your reference template where REFERENCE_DATASET is (and post the image it creates):


#!/bin/tcsh

set dset_src  =  INPUT_DATASET
set dset_ref  =   REFERENCE_DATASET

set opref_img = img_overlap

# ------------------------------------------------------------------------

set dset_cp_ref = __TMP_COPY_REF.nii.gz

# copy the ref and make sure the ref and src have the same space, to
# overlay for visualizing
3dcopy                                     \
    -overwrite                             \
    "${dset_ref}"                          \
    ${dset_cp_ref}

3drefit -space `3dinfo -space "${dset_src}"` "${dset_cp_ref}"

# ------- make image along each viewplane
@chauffeur_afni                        \
    -ulay  "${dset_src}"               \
    -olay  "${dset_cp_ref}"            \
    -pbar_posonly                      \
    -cbar Reds_and_Blues               \
    -set_subbricks 0 0 0               \
    -opacity 5                         \
    -prefix   "${opref_img}"           \
    -montx 1 -monty 1                  \
    -set_xhairs ON                     \
    -label_mode 1 -label_size 3        \
    -do_clean 

# glue separate images together
2dcat                                  \
    -gap 5                             \
    -gap_col 128 128 128               \
    -nx 3 -ny 1                        \
    -prefix "${opref_img}_FINAL.jpg"   \
    "${opref_img}".*.png

echo ""
echo "++ DONE.  Please check out this image for relative alignment/overlap:"
echo "     ${opref_img}_FINAL.jpg"
echo ""

# ... and you can delete the __TMP_COPY_REF.nii.gz file, if you want

exit 0

thanks,
pt

Hi Taylor,
First, this is the code I used:


 @animal_warper  -input T1.nii.gz  -base /home/maestro/Documents/Software/NMT-master/NMT_v1.2/NMT.nii.gz  -atlas /home/maestro/Documents/Software/NMT-master/NMT_v1.2/atlases/D99_atlas/D99_atlas_1.2a_al2NMT.nii.gz


the output of 3dWarp -deoblique -disp_obl_xform_only T1.nii.gz


++ 3dWarp: AFNI version=AFNI_20.2.14 (Aug 21 2020) [64-bit]
++ Authored by: RW Cox
# mat44 Obliquity Transformation ::
      1.000000      0.000000      0.000000       0.000000
      0.000000      1.000000      0.000000       0.000000
      0.000000      0.000000      1.000000       0.000000


Here the output of the code you send me.
Looks there are some issues with the coordinates.
Any thoughts
Thanks for help and time
Fabian

Hi, Fabian-

Great, thanks, I think that all clarifies the situation.

On a preliminary note, I see you are using NMT v1.2, but the the NMT v2.0 is available. See here for images and download information:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/nonhuman/macaque_tempatl/template_nmtv2.html
… and this draft about its benefits of v2.0 (more useful reference coords/dimensions, sharper detail, has the CHARM associated with it as well as the D99, two macaque demos in AFNI exist for it, …), which you might have seen already:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/nonhuman/macaque_tempatl/template_nmtv2.html
and here are the pages for the macaque demos:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/nonhuman/macaque_demos/main_toc.html
And for most applications, I think using the lower-res 0.5mm isotropic NMT v2.0 makes a lot of sense-- certainly if it will be used as part of FMRI processing, because those voxel sizes will surely be much larger. Why spend all the processin time and computer space (the 0.25mm isotropic dsets are 8x larger), if you don’t need it? (Of course, if you do need it, then use the higher res.)

The dataset is not oblique (the “obliquity” matrix is identity + no shift). And actually, I should have noticed this from your GUI screenshots, because there is the “Card” message on the righthand side of each image panel, which is an abbreviation for “data in Cardinal coordinates” and not oblique ones.

However, the input T1w volume is not well-centered around (x, y, z)=(0,0,0). This potentially causes trouble for the initial alignment, because the two datasets are so far off-- see this part of the AFNI Bootcamp alignment talks:
https://youtu.be/PaZinetFKGY?list=PL_CD549H9kgqJ1GDXAs1BWkgEimAHZeNX&t=781
(and, in case it of interest, there are a lot more of these, too:
https://www.youtube.com/channel/UC40RiNZN7_dCuB6Lg7HJl1g
which might be useful, e.g., for curing any insomnia.)
On another practical note, having the datasets far-from-centered on the reference volume will create a problem when applying the warp field later, because it will have to be a huge dataset to cover a bit space (computer memory concerns-- might be too big for the RAM to handle, and so just fail with a “Killed” message).

How to address this? Well, in this particular case, there is a lot of non-brain material around, but we the center of the brain actually looks like it is in the center of the volume. Therefore, we can copy the dset and use this @Align_Centers command (where you provide your template name where TEMPLATE is written):


# copy dset
3dcopy T1w.nii.gz T1w_recent.nii.gz

# apply recentering to dset: edits dset directly (which is why we first copied)
# also stores shift in a separate file (*_shft.1D)
@Align_Centers      \
     -grid                    \
     -no_cp                \
     -dset T1w_recent.nii.gz \
     -base TEMPLATE

If you run the new T1w_recent.nii.gz through the script to check for overlap, how does this one look?

And I will ask, what kind of analysis are you doing with this dataset? Do you have other data (like FMRI) that is aligned with this subject’s anatomical? If so, we might want to shift that, similarly.

–pt

Hi Taylor,
Thanks for the all the advice. I started to see the anfi bootcamp.
I run the command and the script again and looks more better, I see the coronal is not complete overlay. Is there a procedure to improve it?
Other question, you mention that it would be better if I crop the mri to extract the brain. Is there a method to do with afni or is possible to do with matlab and write as nifti and after centered using command you gave me?
In relation to your last question, I am involved in two projects, one about is electrophysiology where I need in the one hand planning a chamber and second locate the recordings sites for previous recordings, this is the current analysis. The second, we are planning in the couple of weeks to do fmri and stimulate with focused ultrasound. All the tools in afni will be very useful.
I will run again the @animal_warper using T1w_recent.nii.gz.
Thanks again
Fabian

Hi, Fabian-

That centering looks like a much better place to start the alignment. I wouldn’t worry about any differences from here-- the alignment procedure will (or should) take care of those. The purpose of this is to just have the datasets starting in a reasonably close overlap, which they certainly appear to have now.

Re. cropping-- yes, you can do this in AFNI. NOooooooooooooooo need to use matlab, yikes… 3dZeropad can be used to place extra slices of zeros around a volume, or to remove slices from sides of the volume (basically, providing negative values for how much padding to do):
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/programs/3dZeropad_sphx.html

At this point for your dset, it might be useful just to greatly reduce the size of files and subsequent processing time. That is assuming, of course, you don’t need the “outside brain” parts of the macaque for further processing? (e.g., positioning electrodes on outer part of scalp?) You list some interesting projects for this dataset, but I am not familiar with them with any personal experience.
For example, to remove extra inf/sup slices, you could try to remove 40 from the “top” and 50 from the “bottom”:


3dZeropad \
    -I -50           \
    -S -40         \
    -prefix T1w_recent_crop.nii.gz \
    T1w_recent.nii.gz

… and I am tooootally guessing at values for how much you could remove. Please visually check that it isn’t too much! And you can remove slices along other axes in a similar way.

And one last thing-- I will put in another plug for using NMT v2.0, esp. the 0.5mm resolution version, for all the reasons suggested in the previous message.

–pt

Hi Taylor,
I did this


3dZeropad \
    -I -80           \
    -S -40         \
    -prefix T1w_recent_crop.nii.gz \
    T1w_recent.nii.gz

I repeated the alignment we did before, no problem
I downloaded the NMTv2 and I did


@animal_warper -input T1w_recent_crop.nii.gz   \  
  -base ~/Documents/Software/NMT-master/NMT_v2.0_sym/NMT_v2.0_sym_05mm/NMT_v2.0_sym_05mm.nii.gz  \
  -atlas ~/Documents/Software/NMT-master/NMT_v2.0_sym/NMT_v2.0_sym_05mm/D99_atlas_in_NMT_v2.0_sym_05mm.nii.gz  \
  -outdir AW_out_sub-002/ -ok_to_exist


and the alignment works perfectly as you can see in the image
Thanks for the help.

Hi, Fabian-

Great, glad that all worked well.

I think the cropping helps a lot with reducing the parameter space within which the computational algorithms check for alignment. It certainly also reduces memory load, and dataset sizes.

Recentering the dset to have reasonable coordinates also helps a lot: sometimes the hardest part of alignment is the first step.

And using the NMT v2 certainly makes sense, particularly with the CHARM atlas available there (as well as the D99). And using the 0.5mm version certainly makes sense in lots of applications as a reasonable voxel size-- if you ever want the higher res, there you will have it, too.

–pt