Overlaying 3dttest results over anatomical and template for mouse brain

Hello. I work with mouse fMRI. After normalizing my functional images with SPM, I am able to see that my normalized results after 3ddeconvolve or 3dttest++, the areas align well with the template crosshair (when opened in new AFNI window) However, I want to be able to align my template ROIs over my functional results instead of using photoshop to try align it properly. I asked before how to resample and got the suggestions to use 3dresample, 3dNwarpApply, or 3dfractionize, but I ran into either errors about template space, or the template ROI lines becoming too undersampled. Here are the 3dinfo for my template and functional scans. My template is in ORIG space, but normalized functional scans in TLRC. I’ve also attached the results of 3dresample. I’ve tried multiple rmodes and get similar results. Even after 3dresample, I am unable to use the resampled template as my underlay for my 3dttest overlay.

Template
Template Space: ORIG
Dataset Type: Anat Bucket (-abuc)
Byte Order: LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode: NIFTI
Storage Space: 19,261,440 (19 million) bytes
Geometry String: “MATRIX(-0.5,0,0,51.03759,0,-0.5,0,35.73753,0,0,1,-58.88757):228,160,132”
Data Axes Tilt: Plumb
Data Axes Orientation:
first (x) = Left-to-Right
second (y) = Posterior-to-Anterior
third (z) = Inferior-to-Superior [-orient LPI]
R-to-L extent: -56.750 [R] -to- 56.750 [L] -step- 0.500 mm [228 voxels]
A-to-P extent: -28.500 [A] -to- 51.000 [P] -step- 0.500 mm [160 voxels]
I-to-S extent: -80.000 [I] -to- 51.000 [S] -step- 1.000 mm [132 voxels]
Number of values stored at each pixel = 1
– At sub-brick #0 ‘?’ datum type is float: 0 to 1997.28

Normalized functional
Template Space: TLRC
Dataset Type: Anat Bucket (-abuc)
Byte Order: LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode: NIFTI
Storage Space: 501,120 (501 thousand) bytes
Geometry String: “MATRIX(1.32,0,0,-79.2117,0,-1.32,0,44.371,0,0,5,-60):120,58,18”
Data Axes Tilt: Plumb
Data Axes Orientation:
first (x) = Right-to-Left
second (y) = Posterior-to-Anterior
third (z) = Inferior-to-Superior [-orient RPI]
R-to-L extent: -79.212 [R] -to- 77.868 [L] -step- 1.320 mm [120 voxels]
A-to-P extent: -30.869 [A] -to- 44.371 [P] -step- 1.320 mm [ 58 voxels]
I-to-S extent: -60.000 [I] -to- 25.000 [S] -step- 5.000 mm [ 18 voxels]
Number of values stored at each pixel = 1
– At sub-brick #0 ‘?’ datum type is float: 0 to 27.2828

Hi-

It is odd that your template space is “ORIG”… What template did you use?

I certainly don’t think photoshop should be used…

To be clear, are you trying to adapt your normalized (in the sense of “aligned”) functional to your template space? If so, you can use:


# copy your file (just to keep the original unchanged) to some new name
3dcopy FUNC_DSET FUNC_DSET_NEW
# change the header info in the new file to have it be "ORIG" space, like your template
3drefit -space ORIG FUNC_DSET_NEW

If, instead, you want make your template be in “TLRC” space, you can do the same things as above just changing “ORIG” → “TLRC” (copy the template, and then use 3drefit to change its header info).

Does that sort out what you want, or is it there something else, too?

-pt

Thank you so much! I am using an in-house template which may be why it’s in ORIG space. After converting my normalized functional to ORIG space, I am able to overlay my results on top of the templates (left image). However, if I use my template as an overlay on top of my normalized anatomical image, the template becomes undersampled (right image). I believe it’s due to the template having a bigger matrix than my images, so the voxels become lost? Is there a way to alleviate this? I’ve tried 3dresample with various rmodes

Also, would it be possible to overlay both my functional and atlas over my anatomical scans?

Thank you for your help

Hi-

So, it is the underlay dataset that sets the grid for displaying. You have a high res and a low res image, but you want the low res one (the EPI) as underlay, then you can make a resampled version that is at a finer grid size: it will look quite similar, but perhaps slightly smoothed (because regridding does that).

So, how about trying this (where you will insert input or output filenames for each DSET* file, but the “IDENTITY” term is actually a keyword to leave as is; each keyword after “-final …” is also meant to be left written as is), where there are some different interpolants you can try, and see what looks best:


# A) use "nearest neighbor" interpolant
3dAllineate                        \
        -input   DSET_LOWRES              \
        -master  DSET_HIGHRES           \
        -prefix DSET_LOWRES_UP_A      \
        -1Dparam_apply IDENTITY        \
        -final        NN

# B) use "cubic" interpolant
3dAllineate                        \
        -input   DSET_LOWRES              \
        -master  DSET_HIGHRES           \
        -prefix DSET_LOWRES_UP_B      \
        -1Dparam_apply IDENTITY        \
        -final        cubic

# C) use "wsinc" interpolant
3dAllineate                        \
        -input   DSET_LOWRES              \
        -master  DSET_HIGHRES           \
        -prefix DSET_LOWRES_UP_C      \
        -1Dparam_apply IDENTITY        \
        -final        wsinc5

# D) use "linear" interpolant
3dAllineate                        \
        -input   DSET_LOWRES              \
        -master  DSET_HIGHRES           \
        -prefix DSET_LOWRES_UP_C      \
        -1Dparam_apply IDENTITY        \
        -final        linear

You can underlay each of DSET_LOWRES_UP_* in the viewer and see what looks most appropriate (each should be fairly quick to calculate.

–pt

ps: if you want a more compact/scripty way to do the above, then this will make 4 dsets, each with the interpolant name in the file name:


#!/bin/tcsh

foreach interp ( NN cubic wsinc5 linear )
  3dAllineate                        \
        -input   DSET_LOWRES              \
        -master  DSET_HIGHRES           \
        -prefix DSET_LOWRES_UP_${interp}      \
        -1Dparam_apply IDENTITY        \
        -final    ${interp}
end 

A couple notes to add on here.

  1. Ulay - warp on demand. You can resample the underlay to a finer grid by changing its voxel size in the “Define Datamode” menu, Warp Ulay on Deman, Ulay Resam mode and Resam (mm). For ROI underlays, you will probably want NN interpolation. This method, while simple, doesn’t do exactly what Paul’s recommendation does. The GUI method increases the voxel resolution but doesn’t guarantee exact voxel correspondence that the -master options force.
  2. Mouse atlas. The mouse atlas you have might just be a coronal one with anisotropic voxels and slices relatively far apart. In the past, I have seen some versions of a Paxinos atlas that have been used in that way. That makes for some interrupted lines like that when showing the atlas as overlay. If you are using single slice volumes, then visualization becomes trickier, but still possible. You might consider using one of the Allen mouse brain templates and corresponding atlases that have higher resolution.
  3. @animal_warper. This program may be used for aligning mouse brains to a template like the Allen mouse brain. The feature_size option there will be much smaller usually depending on imaging resolution and type, so you might set that from 0.05-0.3 mm.

Thank you two for your suggestions. I have gotten the overlay to work with both your suggestions.

As for my atlas, it was a custom made using the allen brain atlas for the ROIs. I see many papers claiming they are using an atlas from the Allen brain atlas, but they don’t have an actual atlas file to download when I checked.

Thank you for the codes as it helped me learn more on how to use afni. It seems using NN creates a blocky image with cubic being very smoothed. wsinc5 seems to be the best mix.

And thank you Daniel for the Define Datamode tip. It’s a quick way to see the atlas over my images. You helped me on my first question here and I looked at animal_warper per your suggestion, but it seems to best work with anatomical images. I’ll give it a try with your settings that you suggest.

Howdy-

Just a brief comment on your visual evaluation of what NN/cubic/wsinc5 interpolations appear to do:
<>

This is a nice summary of the expected behavior:

  • NN = nearest neighbor interpolation. There is no averaging of voxels, just grabbing the value of the voxel from wherever the location to be mapped happens to fall. It can lead to Lego-like viewing, which may not be useful when having continuous/floating point valued datasets, but it is likely necessary when applying interpolation to integer-valued/atlas/ROI datasets. On occasion, it is useful with floating point data, such as EPI, that might have very large distortions.

  • cubic interpolation fits a 3D spline, a smoothly connected function. So, you won’t get blockiness like in the NN case, but you will draw from a fair amount of data around the point that is getting interpolated (most weight from nearby, then slowly dropping off in weighted averaging further away in all directions), which visually results in a fair amount of smoothing.

  • wsinc5 = a weighted form of the sinc(x) = sin(x)/x function. This funny function looks like a damped oscillator (a sinusoid function that gets squashed symmetrically as one goes further from zero). Why is this useful? Well, through the magic of the Fourier Transform, this funny function is one that will have the best edge-preserving properties (and, as a corollary, the least amount of smoothing). There is a tiny cost to pay of introducing/revealing a faint amount of ringing, which is mostly noticeable at the edge of the brain where the signal drops toward zero. Often, this has no practical effect; often, those ringy edges can be removed by some masking procedures, if necessary, but for anatomical images we are usually willing to accept this minor inconvenience for the sake of preserving edges/clarity within most of the volume.

Anyways, you provided a much more succinct summary of this behavior, but this might be useful to know why this happens.

–pt