-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Mattes metric fails for very small voxels #1348
Comments
This is not a perfect test because the images are identical, and the original issue in antspy is intermittent...but I ran it 100 times with the smallest voxels and Mattes fails consistently, and CC does not fail at all. |
Reproduced on Russ' data:
Pairwise calls to antsRegistration work with CC metric, with no failures (antsMotionCorr, not so much, will post more in the other thread). Mattes errors out consistently. This is with dense sampling so not a random initialization thing. A sample of the error, there's a whole bunch of warnings like this
Then
Wait a minute - M is 2x2 - I remember this #756 |
And without a mask, it runs without any error:
|
As I mentioned before, I think it's the scale parameter estimator for the optimizer. When the voxel size gets small, the perturbation blows up transforming the image domain outside of the domain. Still trying to figure out the source of this behavior. |
Okay, so it's the Mattes gradient that is used to estimate the scale parameter which blows up. Note that the measurement seems stable across voxel size. Here's the gradient for the different image pairs:
So I think this should be brought up over at the ITK forum regardless of what we do here. Perhaps @hjmjohnson or @thewtex could weigh in as they have more experience with the ITK development of Mattes (if I'm remembering correctly). One thing we could do here is expose the gradient filter option within all the metrics to the ANTs user which is currently hard-coded as false (for time considerations) although, as noted, that can have a significant impact on performance. For example, when
|
Thanks for the additional option @ntustison, I'll check it out. I'll update the Wiki when I get a chance to document how to deal with these kinds of errors with gradient filtering / workaround with unit change as suggested in ANTsX/ANTsPy#362 . I had a quick look around the ITK forum and didn't see this exact issue. I might try to make a minimal ITK example to highlight the issue. It would be nice to add gradient filtering option to |
Sure, give me a sec and I'll make a pull request. |
Is there a forum thread I can follow? |
I'll cross post when I get to it, but I haven't had time to make an example that only depends on ITK, not including all of ANTs. Maybe in a week or so. If you or anyone would care to attempt it, I was going to base off this and see if I can reproduce the metric gradient problem. |
Following up here, I can't tell if antsRegistration needs this adjustment as well? It only got added to antsMotionCorr. |
It does affect |
I've now done some very rough tests using my custom registration script I use for everything, and a typical registration (multiple scales of rigid/similarity/linear with Mattes + SyNCC) from a 1mm T1 to the MNI 09c model has zero effect on computational time (~10sec faster on 13min with 40 cores) |
I'm thinking to close this now as it seems using the gradient filter fixes these issues? Is there still a need to investigate at the ITK level? |
Sounds good to me. |
Related to ANTsPy issue ANTsX/ANTsPy#362
@ntustison , I found that
antsRegistration
andantsMotionCorr
will fail with very small voxels. In the attached archive, I used RNifti to edit the pixel spacing of the MNI152NLin6Asym template from 2mm to 0.2mm, 0.02mm, 0.002mm, etc. Once the voxel spacing gets sufficiently small, the registration starts to fail with Mattes, but still works with CC or MSQ.With mask (I included the mask because antspy's motion correction uses a mask by default)
Without the mask, it goes one level smaller before failing
Data here: innerSpace.zip
ANTs Version: v2.3.5.post101-g1c5ae7c
Compiled: Mar 23 2022 11:49:51
The text was updated successfully, but these errors were encountered: