Giter Site home page Giter Site logo

Comments (4)

gdevenyi avatar gdevenyi commented on June 16, 2024 1

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

from ants.

cookpa avatar cookpa commented on June 16, 2024 1

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

from ants.

gdevenyi avatar gdevenyi commented on June 16, 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

from ants.

nickcicero18 avatar nickcicero18 commented on June 16, 2024

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

from ants.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.