Support multiple metrics and regularizations, add tests and backward compatibility ("legacy hack")#1453
Support multiple metrics and regularizations, add tests and backward compatibility ("legacy hack")#1453N-Dekker wants to merge 11 commits into
Conversation
N-Dekker
commented
Jun 19, 2026
- Cherry-picked pull-request ENH: Add support for multiple metrics and regularization #1437 from @Leirbag-gabrieL (followed by clang-format)
- Originally based on pull request ENH: Add support for multiple metrics and regularization #482 by @alvarez-pa
- Addresssing issue Multiple metrics and regularization #481 by @alvarez-pa
- Included backward compatibility ("legacy hack" support), following comment ENH: Add support for multiple metrics and regularization #1437 (comment) by @stefanklein
- Added unit tests
| // Parameters in alphabetic order: | ||
| { "FixedImagePyramid", ParameterValuesType(3, "FixedRecursiveImagePyramid") }, | ||
| { "ImageSampler", ParameterValuesType(3, "Random") }, | ||
| { "Interpolator", ParameterValuesType(3, "BSplineInterpolator") }, | ||
| { "MaximumNumberOfIterations", { "2" } }, | ||
| { "Metric", { "AdvancedNormalizedCorrelation", "AdvancedNormalizedCorrelation", "TransformBendingEnergyPenalty" } }, | ||
| { "MovingImagePyramid", ParameterValuesType(3, "MovingRecursiveImagePyramid") }, | ||
| { "Optimizer", { "AdaptiveStochasticGradientDescent" } }, | ||
| { "Registration", { "MultiMetricMultiResolutionRegistration" } }, | ||
| { "Transform", { "TranslationTransform" } } })); |
There was a problem hiding this comment.
@mstaring @stefanklein This unit test is intended to check that the original "legacy hack" still works. Can you please check that this is indeed the way the "legacy hack" worked? I mean, was the trick to add a dummy fixed image, a dummy moving image, an extra "FixedImagePyramid", an extra "MovingImagePyramid", an extra "ImageSampler", and an extra "Interpolator"?
|
@stefanklein @mstaring Now I'm starting to doubt if a transform based metric like "TransformBendingEnergyPenalty" can work without having its own images. The "GetValue" member functions of TransformBendingEnergyPenaltyTerm (for example Looks like the logic is implemented in So when the i-th metric requires to use an image sampler (including "TransformBendingEnergyPenalty") and there is no "i-th sampler", the metric may use "the zeroth image sampler". So then, I guess this pull request should be OK, right? |
Removed two unnecessarily typedef's from the public interface of CombinationImageToImageMetric.
Following "Use the prefix form (`++i`) of the increment and decrement operators unless...", https://google.github.io/styleguide/cppguide.html#Preincrement_and_Predecrement Also removed unnecessary `this->` from those cases.
Avoided repeatedly calling GetNumberOfInterpolators().
Avoided repeatedly calling GetNumberOfFixedImagePyramids() and GetNumberOfMovingImagePyramids().
Avoided repeatedly calling GetNumberOfFixedImages() and GetNumberOfMovingImages().
Based on issue #481 "Multiple metrics and regularization", Pablo Alvarez (alvarez-pa), Jun 15, 2021.
Allowed users to add "dummy" images when having more metrics than images (which was a "hack" before it was officially supported to have more metrics than images).
They appear unused.
ecc68c0 to
8774750
Compare
|
elastix supports the following 23 metrics. I guess we should check which metrics do or don't use the input images. Because it appears that transform based metrics (like "TransformBendingEnergyPenalty") may still use the images. I think CheckOnInitialize should become less strict than the current (main/release) version, but I doubt if that should be based on whether or not metrics are transform based. Four metric classes are derived from TransformPenaltyTerm (which is itself derived from AdvancedImageToImageMetric): I think the only thing that matters is whether |