-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Inconsistency problems with Registration of anatomical images #1816
Comments
Thanks for the examples. I will try to look when I get time. From reading the description, I would suggest checking the header info of the problematic images vs ones that work consistently. ANTs 2.1 vs 2.5 has different ITK versions, and ITK has changed the way it handles NIFTI headers. So data that has different sform or qform parameters can behave differently on different versions. |
Thanks for your quick reply! I checked the nifit headers from my mask and anat files with fslhd. From the anatomical i got this:
from the mask I got this:
These numbers are pretty consistent on all anatomical and mask files. |
I don't think that one line of sform would be enough to cause this problem. I can check in more detail but could you please isolate the one command that is going wrong and make a script that just runs that command with the sample input? I think this involves "sub-aRi114_ses-1_T2w_N4_dn.nii.gz", which you included, and the fixed image "/project/4180000.24/analysis_wessel/DTI/template/DSURQE_100micron_average.nii.gz", which I don't think is there. |
One other thing that comes to mind is that in animal data, the small voxel sizes sometimes expose numerical problems with optimizers. Example: #1348 So one thing I would test is if the two versions behave differently if the spacing of the images is changed. Another thing: spatial units. The xyzt_units field may be important, this was another relatively recent fix to ITK (InsightSoftwareConsortium/ITK#4595) |
I've added the script in this message. Also I added an extra folder in the drive called sub-aRi114, this also contains the template and the template mask. Script is changed so it works if working directory is called sub-aRi114 :) But the weirdest thing now is that I reran the analysis to check if it ran properly and now i get proper anatomical registration... I double checked if I was not using a different ants version but twice it gave proper anatomical registration. Their should be no difference with the earlier scripts that I used for this subject for input files or anything... |
Regarding the spacing: what do you mean exactly? should I increase the apperent voxel size or how would I do that? Regarding the xyzt_unit values: I found out that my anatomicals and anatomical masks have a xyzt_units value of 2. My template anatomical also has a value of 2. The template mask actually has an xyzt_units value of 0 but the dilated version of this mask (which I use for my script) has a value of 10. My anatomical masks also have a xyzt_units value of 10. Could this potentially cause problems bc the xyzt_units values are not comparable? |
was not my intention to close this problem woops, still have the problem |
turning on the Gradient Filter for MI metrics as as suggested in #1348 still resulted in some bad registrations such as this one |
You can use
I think that's OK. The xyzt_units is inherited from the old Analyze format, it's a byte where the first three bits describe space and the next three describe time. The space bits should be 2 for mm. 10 means mm for space and s for time. 0 means unknown, which I believe defaults to mm. |
Interesting. I guess it could be stochastic still. If you can run it a bunch of times and it's consistent, it suggests a hidden problem somewhere in the preprocessing. To run it myself, I need a really minimal example, just this
and the fixed, moving images and their masks. Then I will see if I can notice anything in the registration itself. |
When I do work in animal land, a major problem is the conversion of the data coming off the scanner is often not properly structured to NIFTI format. If you are using bruker data, the only known reliable converter is https://github.com/BrkRaw/brkraw. For other manufactures I have worked with I had to scan calibration objects and then fix data after-the-fact with data re-ordering and flipping. The viewer ITKsnap is standards-compliant and interprets data the same way the latest ANTs IO reader does for NIFTI, so it is an ideal tool to use to confirm that your fixed and moving images are properly standards-compliant in orientation, before you attempt alignment. Finally, you may be interested in which I developed as part of my work to make the ANTs registration tools more consistent across voxel sizes and species. I see N4 being used in this set of commands as well, I would note that I have found anisotropic data has issues in some places because of subsampling assumptions. I also isotropize data and adapt tools to work at "real world" scalings (mm) instead of the voxel scalings to avoid issues with that. |
Hmm okay, next monday I'll try to run it like, 100 times to see if that is the case.
moving image: sub-aRi114_ses-1_T2w_N4_dn.nii.gz I believe this is everything you need then! let me know if I missed something.
Thanks for the advice! Will look in to it asap! |
I also use brkraw luckily!
Oh this is a good one, like mentioned above, after the weekend I'll immediately check it out!
Idem for this, will check it out after the weekend! |
This is exactly where switching to my "mm based" representation of the scale space really helps, the default subsampling suggestions for ANTs fall over pretty quickly for anisotropic data if you don't deeply understand what it does. |
I looked at the images in ITK-SNAP and the masks appeared correctly oriented. BTW, using dense sampling for the metric disables the random perturbation of the sample points (as well as adding more sample points, which probably also helps). So run-to-run variability should be reduced. |
hmm I dont think I fully comprehend what you mean, but that is probably because of my lack of knowledge about this concept! From what I understand you also suggest that upscaling to 1mm scale would help because ANTs would better be able to do the regs, correct? |
hmm intersting. So far from what I have seen today fixing the sform parameters in the NIFTI headers decreased the amount of failed regs per try with 50%. So still stochastically they fail, but they fail less often. Im gonna try the dense sampling metric and without 8x shrink factors now! |
No, there's no need to rescale. You just need to understand that smoothing and subsampling happens by default in voxel-spacing, and if your data is anisotropic, that will carry through to how the subsampling and smoothing is applied during registration. This causes issues in two ways
I've tried to tackle these issues by wrapping the registartion in a bunch of python math to use the physical dimensions of the images as well as their voxel sizes to define a more coherent scale-space to step through during registration. |
aaaah okay I think Im beginning to understand. So because of the anisotropic voxels, smoothing happens unevenly across different directions and therefore you get uneven smoothing and deforming (if that is the correct term) of the original image. By defining smoothing over mm, so in real space instead of voxels, the program will adjust the amount of voxels it needs per direction to get an even distance across all directions and therefore you will have homogenous smoothing and thus no deforming (again correct me if im wrong) of the image. Am I getting closer to what you mean? So far I have ran a registration round with specifically defining the orientations for all used niftis (masks and anatomicals), removing the 8x shrink factor and using dense sampling metric. So far, all anatomical registrations were succesful! DWI registrations were not always right for all subjects yet. Im gonna rerun with the same settings to check if the results are now indeed more consistent as @cookpa suggested! Thank you all for you advice so far, it has been really helpful and educative! |
These smoothing sigmas are too large if you're working with animal data represented with true resolution. Here's what my reg script would've approximately done internally: (min is minimum voxel size, max is maximum physical extent of the image) $ ants_generate_iterations.py --min 0.15 --max 20
--convergence [ 500x500x180x60x20x20,1e-6,10 ] \
--shrink-factors 4x4x3x2x1x1 \
--smoothing-sigmas 0.375x0.3x0.22499999999999998x0.15x0.075x0.0mm @cookpa Regarding the random sampling component and masks, I think there was some concern with how masking is handled during random voxel sampling. I didn't dig into it because I only ever used dense sampling, but maybe that's also an impact here? |
This is a good point, I believe the sampling is done on the whole volume and then points outside the intersection of the masks are discarded. So there can be fluctuations in the exact number of sample points. IMO dense sampling is the way unless there is a particular need to mitigate sampling bias |
yeah when this seems more logic indeed, really didn't think about difference between vox and real distance, but seems pretty logic!
Since I use the Dense Sampling in my analysis faulty anatomical registrations were virtually absent, maybe 1 or 2 subjects. Only my DWI-> anatomical registrations were not great so my DWI->anatomical->template were a bit messy as shown below I hope the server is not as busy today as yesterday, then I try the dense sampling strategy a few times to see how consistent it is :) |
Those are based on your minimal voxel size and the "average" size for a mouse brain, so they should be OK to use. Of course, if you used my reg scripts directly, that would all be handled internally ;)
Those numbers say the maximum number of optimization steps at a given shrink/smooth, provided they don't meet the 1e-6 convergence criteria first. They're rarely met anyways because convergence happens first.
These are all optimizations on top of dense sampling, its definitely a good place to start. |
Okay so I have just ran a few hundred runs with the following settings: 12 times I ran all my 100 subjects. Of these 12 runs per subject there were a total of 4 failed runs with 1 subject being over represented ( 3 times, aRi013). So 4/1200 runs failed. But I found that quality of registration could vary a lot between subjects and runs. All in all does this show that for the anatomical registrations Dense Sampling solved indeed let to more consistent results and solved my initial problem, so thank you a lot! :) Now only my DWI -> template registrations are left. I tried the same strategy with Dense Sampling and not too big of shrink factors, but sadly it did not work yet. If you have any advice on this I am happy to hear it! I'm gonna take a look at those scripts of yours to see if they can help with it @gdevenyi :) |
Yes, it would matter. You know your data best, I was just making a suggestion. Sounds like you have a good rationale to use mean b=0. Anyway, I would not use antsRegistrationSyN.sh at all, I would use a custom command fixed=t2.nii.gz
fixed_mask=t2_mask.nii.gz
moving=mean_b0.nii.gz
antsRegistration --dimensionality 3 --float 0 -a 0 -v 1 \
--output [dwi2anat,dwi2anatWarped.nii.gz] --interpolation Linear --winsorize-image-intensities [0.005,0.995] --use-histogram-matching 0 \
--initial-moving-transform [${fixed},${moving},1] \
--transform Rigid[0.1] --metric MI[${fixed},${moving},1,32] \
--convergence [50,1e-6,10] --shrink-factors 1 --smoothing-sigmas 0vox \
--masks [${fixed_mask}, none] To combine warps, you can use If you try to do anything non-rigid with antsRegistration, I would make b0 the fixed image, t2w the moving. Note this affects the order of transforms when you apply warps. Then run rigid. Use the rigid output as an intial transform to an affine / deformable step, with the There is a |
See also https://github.com/ANTsX/ANTs/wiki/Dimensionality-or-ImageDimension-option-in-ANTs for more on what ANTs calls the "ImageDimension" and why it's often correct to use |
Thank you for your suggestion! Been busy collecting data today so hadn't had the time yet, but will try asap will look at these suggestions asap :)
I got a feeling that non-linear deformation only increased troubles with the DWI registration. I tried to create a manual call myself, but that was not very succesfull as the b0_temp mean got very skewed, looking like the affine part went very wrong. I can try both and see what works best. I think with the using the T2w as moving and b0 as fixed, in the end I should apply the inverse transform on the b0 to register it to the t2w right? Or am I wrong?
Also thanks for this suggestion, perhaps if everything else will not work its worth taking a look. I got some stuff to continue working with! Will let you know if it improves the registrations :) |
Operating system and version
CentOS Linux 7 (Core)
CPU architecture
x86_64 (PC, Intel Mac, other Intel/AMD)
ANTs code version
ANTs Version: 2.1.0.post370-ga466e
ANTs installation type
Other (please specify below)
Summary of the problem
Hello everybody. So I am using ANTs on a higher performance cluster (torque) at the DCCN in Nijmegen.
I've been trying to register DWI rodent MRI data onto an existing template (DSURQE) to be able to analyse the
FA and MD maps. I'm following the following strategy to achieve that:
For every subject I first register anatomical (T2) image onto a template anatomical image (T2) using antsRegistration and create a
composite transform using ComposeMultiTransform.
Then I register the subject DWI data onto the subject anatomical data. To do this I take the temporal mean of one of
the b0 maps of the DWI data (after corrections, see code) as proxy for the whole DWI image.
I then apply both composite transform on the DWI data, so in practice i register DWI onto anatomical and the resulting
image onto the template, so that my DWI data is registered onto the template.
To improve the processing time I am using masks that I created using an AI program called BEN for all subjects.
These masks I dilate a little using fslmaths so they cover the brain and the surrounding tissue to get a better
brain/no-brain contrast.
Im facing a problem when it comes to the anatomical registrations. With the same ANTs version I am getting very inconsistent
anatomical to template registrations. I've tried doing less non-linear iterations, different metrics for different
transforms but when looking through the documentations I actually can't find what I am really doing wrong
with my parameters. For some subjects an anatomical registration works when I don't use masks, but for other subjects
the anat to template registration then doesn't work anymore. There really is not a thing to point towards that might cause failing of the registration, as far as I know. It feels like some stochasticity causes registrations to work or not. In the I resorted to using older ANTs versions and here some subjects that kept failing seemed to work.
Most subjects had proper anatomical to template registration with an older ANTs version (ANTs/2.1.0.post370-ga466e
).
However for some that didn't work I used ANTs/2.5.1-gb909304 or ANTs/2.5.3-g98bf76d. For all versions I used the exact same script.
Now I am a bit confused as to what could be the reasons that my registration do not work as I expect them to be. There
are some minor quality difference between some subjects, but most of them should be fixed by the preprocessing steps applied
to the anatomical images. It just seems weird to me that for the same subject registration work on older versions of
ANTs but not on newer versions. Therefore I was wondering if this could be caused by faulty functioning of
the ANTs built that I use, faulty quality of my input data or if it is just the nature of working with this kind of data. It really feels like some registrations only work by some stochasticity or something... I was wondering if someone could explain how ANTs exactly handles data and whether these inconsistencies might arise from my side (bad preprocessing or registration parameters, or approach) or that it is something that really is part of ants.
For this specific subject registration with ants/2.1.0 looks like this:
and for ants/2.5.3 like this:
Commands to reproduce the problem.
Here is the anatomical to template registration call:
Output of the command with verbose output.
script_sub-aRi114_output.txt
--> with ants/2.1.0
script_sub-aRi114_output.txt
--> with ants/2.5.3
Data to reproduce the problem
Here is a link to an example of a full script and the full file output for the same subject with different ANTs versions: https://drive.google.com/drive/folders/1Bv2Hkb9N0GpWx60-kG-3HFcWXMOfCldT?usp=sharing
The text was updated successfully, but these errors were encountered: