Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing EPI to T1 MPRAGE registration #1734

Open
nickcicero18 opened this issue May 1, 2024 · 4 comments
Open

Optimizing EPI to T1 MPRAGE registration #1734

nickcicero18 opened this issue May 1, 2024 · 4 comments

Comments

@nickcicero18
Copy link

Operating system and version

CentOS Linux 7 (Core)

CPU architecture

Unknown

ANTs code version

ANTs Version: 2.1.0.post764-g8bed0

ANTs installation type

Compiled from source

Summary of the problem

Hi,

I have a partial FOV EPI dataset that I am trying to register to the T1 MPRAGE with the goal of optimizing the registration in the brainstem, particularly at the boundary between the 4th ventricle and posterior brainstem. The partial FOV EPI has distortion in the A-->P direction, with some anterior in the anterior part of the brainstem, thus I have been using SyN to try and best register these two together. My approach that I will describe below has worked for most subjects so far, but I have a few subjects where despite many iterations of antsSyN the final registration is still several millimeters off (i.e. the registered functional has the 4th ventricle several slices anterior to the anatomical image). I have tried a few of the different trouble shooting suggestions I've seen in other GitHub issues, but none of have worked yet. I would like to first get a sanity check that I am not doing anything obviously wrong in my code, as well as the way I am trying to optimize over the brainstem. Second, if anyone has suggestions on how to go about iterating through the different registration steps I do to optimize the brainstem registration that would be helpful. I am somewhat new to ANTs so I don't have the best understanding about all of the parameters.

To optimize over the brainstem, I have been manually drawing binary masks in both anatomical and functional spaces covering the 4th ventricle and much of the brainstem. After Rigid and Similarity steps using just the brain masks to get the EPI somewhat aligned to the MPRAGE, I then use these brainstem masks in the affine and SyN steps of my antsRegistration call to optimize over the brainstem. Again, this has worked for many subjects with the attached script, but just a few I am having a hard time fixing.

Attached is:

  • the script I run (example_ants_script.sh)
  • verbose output of the script (ants_script_output.txt)
  • input files for the script
  • output registration files (ants_output.mat, ants_output.txt, ants_output.lta)

I'm happy to provide any other information that would be helpful.

Thanks,
Nick

Commands to reproduce the problem.

example_ants_script.sh.zip

Output of the command with verbose output.

ants_script_output.txt

Data to reproduce the problem

ants_example.zip

@gdevenyi
Copy link
Contributor

gdevenyi commented May 1, 2024

Hi,

(Note the script and example data have brain.nii and brainmask.nii mixed up naming wise, I have preserved this in my example)

Here's my crack at optimizing the registration, changes made

  • use the EPI brainmask to fully extract the EPI, so that there is "1:1 tissue correspondence" at least for the FOV of the scan
  • BSpline interpolation because its much faster than Lancoz and very nearly as accurate (warning, this produces negative background values on resample you need to handle)
  • don't winzorise the intensities, there's no huge outliers in either
  • don't histogram match, they are not the same modality so I don't think this is appropriate (this is better for matching say, T1 FLASH to T1 MPRAGE)
  • these scans should be "pre aligned" since they're the same subject same session, therefore don't do a COM --initial-moving-transform
  • always use dense sampling and gradient filter: Mattes[ ${target},${moving},1,32,None,1,1 ]
  • These are the same subject, use only Rigid transforms
  • These are the same subject, don't use too much smoothing subsampling
  • Do multiple stages of rigid, first aligning the whole-brain, and then refining alignment with the ROI mask
  • Use the brainstem mask for the SyN registration

Note that at the end of this, the intention is to align JUST the brainstem, if I were doing a full registration where I want to explicitly also focus on the brainstem, I would do a SyN without the masks, and then refine the SyN in the masked area again.

This hard-coded script is based on the outputs from my generalized registration script antsRegistratioN_affine_SyN.sh from https://github.com/cobralab/minc-toolkit-extras/

P.S. The MPRAGE is a bit over-padded which will causes excess unneeded calculations that need to be done, cropping the FOV to be tighter would speed up the script.

#!/bin/bash

set -euo pipefail

set -x

target=brainmask.nii
moving=EPI_Tmean_extracted.nii.gz
output=ants_output  # Remove the extension if any.

target_mask_brainstem=brainstem_mask_anat.nii.gz
moving_mask_brainstem=brainstem_mask_EPI.nii.gz

ImageMath 3 EPI_Tmean_extracted.nii.gz m EPI_Tmean.nii.gz EPI_Tmean_mask.nii.gz

antsRegistration --dimensionality 3 --float 0 --verbose 1 \
        --output [$output,${output}.nii.gz] \
        --interpolation BSpline[5] \
        --transform Rigid[ 0.1 ] \
                --metric Mattes[ ${target},${moving},1,32,None,1,1 ] \
                --convergence [ 500x500x225x75,1e-6,10 ] \
                --shrink-factors 5x4x3x2 \
                --smoothing-sigmas 2.5x2.0x1.5x1.0mm \
                --masks [ NOMASK, NOMASK ] \
        --transform Rigid[ 0.1 ] \
                --metric Mattes[ ${target},${moving},1,64,None,1,1 ] \
                --convergence [ 225x75x25x25,1e-6,10 ] \
                --shrink-factors 3x2x1x1 \
                --smoothing-sigmas 1.5x1.0x0.5x0.0mm \
                --masks [ NOMASK, NOMASK ] \
        --transform Rigid[ 0.1 ] \
                --metric Mattes[ ${target},${moving},1,64,None,1,1 ] \
                --convergence [ 75x25x25,1e-7,10 ] \
                --shrink-factors 2x1x1 \
                --smoothing-sigmas 1.0x0.5x0.0mm \
                --masks [ ${target_mask_brainstem},${moving_mask_brainstem} ] \
          --transform SyN[ 0.1 ] \
                --metric CC[ ${target},${moving},1,4,None,1,1 ] \
                --convergence [ 500x180x60x20x20,1e-6,10 ] \
                --shrink-factors 4x3x2x1x1 \
                --smoothing-sigmas 2.0x1.5x1.0x0.5x0.0mm \
                --masks [ ${target_mask_brainstem},${moving_mask_brainstem} ]

Couldn't attach the file here, too large, but here's the ants_output files (resampled image, affine file, forward/reverse warp fields)

https://we.tl/t-EKohDy5p1j

@cookpa
Copy link
Member

cookpa commented May 1, 2024

I ran the script as-is and it looks good to me. There is an element of randomness so results can vary, but I'm also using an up-to-date antsRegistration.

image

The bottom panel comes from running

antsApplyTransforms -d 3 -i EPI_Tmean.nii.gz -o ants_outputAffineOnlyWarped.nii.gz -r brainmask.nii \
  -t ants_output0GenericAffine.mat -n LanczosWindowedSinc

I always do this so I can see how well aligned the affine transform gets us. In this case it seems pretty close.

If it's failing to capture the nonlinear deformation there are a few things to try, in no particular order

  • Boosting the SyN step size to 0.2

  • Starting SyN at one level downsampled, ie -f 2x1

  • BSplineSyN, this lets you smooth the update field with a spline in 3D, rather than an isotropic kernel. So you can allow more deformation along the AP axis. This can let you use a larger step size without having too much deformation in the other directions.

  • Using landmark points in both images as an additional metric.

I also noticed that contrast range of the anatomical image is pretty heavily truncated. All the voxels in red here have constant intensity, and that's before the registration winsorization is applied

image

@gdevenyi
Copy link
Contributor

gdevenyi commented May 1, 2024

I also noticed that contrast range of the anatomical image is pretty heavily truncated.

Metadata says the file is post-Freesurfer, so its had lots of manipulation done to it

@nickcicero18
Copy link
Author

@cookpa @gdevenyi thank you both for your quick responses and insightful comments. I'll give these suggestions a try! Thank you again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants