Comments (4)
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)
from ants.
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](https://private-user-images.githubusercontent.com/611507/327182859-787694bb-56ed-4d55-a66f-40334d189c00.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg1MzA0ODEsIm5iZiI6MTcxODUzMDE4MSwicGF0aCI6Ii82MTE1MDcvMzI3MTgyODU5LTc4NzY5NGJiLTU2ZWQtNGQ1NS1hNjZmLTQwMzM0ZDE4OWMwMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYxNlQwOTI5NDFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01YzQ2NjcyNDlmN2QzYmM5YjAxMmU2ODEyM2VlNmI4MDI4ZDU2NGEyZTU3YzAxOWJjMzAyNWNmOWI1MTIyZWZkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.8k3QwRnhdlxNExhZCgYTmmo5rfEPoEeytpH5a_yDU6M)
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](https://private-user-images.githubusercontent.com/611507/327187962-99113dd7-4878-47f3-a1a1-82adb4808581.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg1MzA0ODEsIm5iZiI6MTcxODUzMDE4MSwicGF0aCI6Ii82MTE1MDcvMzI3MTg3OTYyLTk5MTEzZGQ3LTQ4NzgtNDdmMy1hMWExLTgyYWRiNDgwODU4MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYxNlQwOTI5NDFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02YTAyNTVkYWM4YTk1YTRhZWQ4NWY2MzU1NGJmNzE2MWY1ODdjZmZmNjU4OWNjYTYzNjRmZmEzNTM5ZTdiNGFlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.m7aeAs81OwEeGKfaFU0cRjM3Hy4fNuTwMPYX9VoOKfA)
from ants.
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.
@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)
- antsApplyTransforms allows `-d 4` with a 3D warp field HOT 2
- Use ants image in docker to complete registration HOT 19
- Can't extract brain from skull on T1-weighed MRI images HOT 13
- Segmentation-aware template building HOT 3
- ANTs and SPM compatibility HOT 3
- Running into "error while loading shared libraries" while using antsApplyTransforms HOT 2
- Multivariate template construction with > 10 modalities HOT 2
- Deprecation of LabelGeometryImageFilter (used in LabelGeometryMeasures) HOT 12
- Error message at antsApplyTransform HOT 6
- running ANTs binaries on a windows laptop reports error: "could not find VCRUNTIME140_1.dll" HOT 2
- ResampleImage usage HOT 3
- Building template in ANTs HOT 6
- Can't open the last modality with antsMultivariateTemplateConstruction2.sh HOT 3
- REQUEST: rewrite the readme? HOT 10
- A Question About Registration Issues Due to Extensive Brain Structure Absence Caused by Developmental Problems HOT 7
- how to interpret the transformation matrix? HOT 2
- use in docker HOT 4
- Atropos - Segmentation fault (core dumped) HOT 2
- About interpolation with tranfomation matric by Ants HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ants.