Repository navigation
BUG: Guard NormalizedCorrelationImageFilter zero-variance NaN - #6612
hjmjohnson merged 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| Modules/Filtering/Convolution/include/itkNormalizedCorrelationImageFilter.hxx | Adds exact-zero guards for template and neighborhood norms, but NaN norms can still bypass the guard after floating-point cancellation. |
| Modules/Filtering/Convolution/itk-module.cmake | Adds the GoogleTest test dependency needed by the new test driver. |
| Modules/Filtering/Convolution/test/CMakeLists.txt | Registers a new GoogleTest driver for the Convolution module. |
| Modules/Filtering/Convolution/test/itkNormalizedCorrelationImageFilterGTest.cxx | Adds regression tests for exact zero-variance template and neighborhood cases. |
Reviews (1): Last reviewed commit: "BUG: Guard NormalizedCorrelationImageFil..." | Re-trigger Greptile
d4930a0 to
db1ca36
Compare
A constant template or a locally-constant neighborhood makes the template-norm or neighborhood-norm denominator zero, so the correlation division produced NaN (or Inf on rounding). With double pixels the variance can also cancel to slightly negative, making the norm itself NaN and bypassing an exact-zero test. Both sites now test !(norm > 0) and return zero, the conventional value for undefined correlation. Addresses item B46 of InsightSoftwareConsortium#6575.
db1ca36 to
86df3ba
Compare
|
Restructured the zero-variance template guard for performance (86df3ba): instead of a per-element ternary in the normalization loop, the degenerate case now early-outs of |
|
A high-effort automated review of this branch surfaced a few items worth addressing before merge. I could not push fixes directly because this PR has maintainer edits disabled ("Allow edits by maintainers" is unchecked — enabling it would let me apply these for you). Findings (ranked)
|
I’ve enabled it. Thanks! |
NormalizedCorrelationImageFilterdivides by a norm that is exactly zero for a constant template or a locally-constant neighborhood, producing NaN or Inf. Addresses B46 of #6575.Root cause
Three unguarded divisions in
itkNormalizedCorrelationImageFilter.hxx:/ kat:130(the template norm) andnumerator / denominatorat:192and:228(the neighborhood norm, duplicated verbatim in the mask and no-mask branches). Each denominator is exactly zero when its signal has zero variance — a constant template, or a neighborhood that falls entirely inside a constant region of the image.All three now yield the filter's existing
zerosentinel. That is not a new convention:origin/mainalready returnszerofor pixels outside the mask ("Not under the mask. Set the normalized correlation to zero."). This routes two more undefined cases through the same sentinel instead of through NaN/Inf. The ambiguity that0is also a legitimate correlation value for two orthogonal non-constant signals is pre-existing and unchanged.Local validation
New GoogleTest
itkNormalizedCorrelationImageFilterGTest.cxx(the module had no GTest driver).ConstantTemplateProducesFiniteZeroOutput— fail-before:-naneverywhere. Pass-after: all0.ConstantNeighborhoodProducesFiniteZeroOutput— fail-before: a mix of-nanandinf(the numerator is not bit-exactly zero after normalization rounding, so0/0sometimes resolved to±inf). Pass-after:0.ConstantNeighborhoodUnderMaskProducesFiniteZeroOutput— covers the duplicated mask branch. Fail-before:inf. Pass-after:0.ctest -L ITKConvolutionwith ExternalData fetched, atmainand at the branch: 44/45 pass at both, nothing flipped (the one Not Run isITKConvolutionKWStyleTest, whose tool is not built locally).itkNormalizedCorrelationImageFilterTest, the only baseline consumer of this filter in the tree, reportsImageError = 0at both states — itssf4.png/circle.pngfixture never drives the filter into a zero-variance case, which is consistent with the fact that no existing baseline contains non-finite pixels.AI assistance