BUG: Fix bisection midpoint in ThresholdMaximumConnectedComponents#6595
Merged
thewtex merged 1 commit intoJul 13, 2026
Conversation
The initial midpoint used span/2 instead of lowerBound + span/2, matching the in-loop update formula only when lowerBound is zero. For unsigned pixel types with a nonzero lower bound, the subtraction that follows wrapped, corrupting the initial search bounds. Addresses item B13 of InsightSoftwareConsortium#6575.
Contributor
|
| Filename | Overview |
|---|---|
| Modules/Segmentation/ConnectedComponents/include/itkThresholdMaximumConnectedComponentsImageFilter.hxx | Corrects the initial threshold-search midpoint so nonzero image minima stay inside the search range. |
| Modules/Segmentation/ConnectedComponents/test/CMakeLists.txt | Adds the new threshold maximum connected components GTest source to the existing driver. |
| Modules/Segmentation/ConnectedComponents/test/itkThresholdMaximumConnectedComponentsImageFilterGTest.cxx | Adds a focused unsigned-int regression test for large-offset translation invariance. |
Reviews (1): Last reviewed commit: "BUG: Fix bisection midpoint in Threshold..." | Re-trigger Greptile
thewtex
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seed the bisection search at
lowerBound + span/2instead ofspan/2inThresholdMaximumConnectedComponentsImageFilter. Addresses B13 of #6575.Root cause
itkThresholdMaximumConnectedComponentsImageFilter.hxx:107:The seed is the span, correct only when
lowerBound == 0. For a nonzero lower boundmidpointlands belowlowerBound, so the next line's unsignedmidpoint - lowerBoundwraps and corrupts the initial search bounds before the loop starts. The in-loop update at:147-148already uses the correctlowerBound + (upperBound - lowerBound) / 2form — the fix makes the seed use the same rule.Local validation
New GoogleTest
ThresholdMaximumConnectedComponentsImageFilter.BisectionIsTranslationInvariant: the same image, translated by an intensity offset of 3,000,000,000 (unsigned intpixels), must yield the same object count and a threshold shifted by exactly that offset.Fail-before:
Pass-after:
[ PASSED ] 8 tests.(whole module GTest driver)ctest -L ITKConnectedComponents: 15/16 pass, includingitkThresholdMaximumConnectedComponentsImageFilterTest1/Test2(real-image baselines) — unchanged. The 1 non-pass isITKConnectedComponentsKWStyleTest, "Not Run" (KWStyle binary absent in this build tree; pre-existing, affects all KWStyle tests).AI assistance