BUG: Fix LabelMap and label-statistics correctness bugs from issue 6575#6590
Open
hjmjohnson wants to merge 6 commits into
Open
BUG: Fix LabelMap and label-statistics correctness bugs from issue 6575#6590hjmjohnson wants to merge 6 commits into
hjmjohnson wants to merge 6 commits into
Conversation
In KEEP mode the deque of collision-deferred objects was declared outside the per-input loop and drained without being cleared, so with three or more inputs an object deferred while merging one input was pushed again while merging the next -- aliasing one object under two label keys. Declare the deque inside the loop. Issue InsightSoftwareConsortium#6575, item B40.
…Overlay The SLICE_CONTOUR slice-radius loop tested the write cursor against SliceDimension where it meant the read index, so SliceDimension 0 left the radius all-zero and drew no contour at all. Test the read index. Issue InsightSoftwareConsortium#6575, item B41.
With no matching object lines the crop bounding box kept its min/max sentinels, so the region size computation overflowed (undefined behavior) and the filter allocated a 2x2 image at a nonsense index. Use an empty region when no lines are found. Issue InsightSoftwareConsortium#6575, item B42.
The removal loop condition was inverted (while (it.IsAtEnd())), so the pass never ran and an object whose every pixel was claimed by a higher-priority object survived with zero lines. Adds a GoogleTest. Issue InsightSoftwareConsortium#6575, item B43.
The last-resort gap scan compared the walked label against lastLabel to detect a full map, but on a completely full range that test never held, so no free label was assigned and AddLabelObject silently overwrote the object's own entry. Track whether a free label was found. Adds a test. Issue InsightSoftwareConsortium#6575, item B44.
Weighted elongation and flatness used unclamped principal moments and a single shared guard, so an indefinite weighted covariance from a signed feature image produced NaN where ShapeLabelMapFilter returns 0. Clamp the moments and guard each ratio, matching ShapeLabelMapFilter. Adds a test. Issue InsightSoftwareConsortium#6575, item B45.
Member
Author
|
@greptile review |
Contributor
|
| Filename | Overview |
|---|---|
| Modules/Filtering/ImageFusion/include/itkLabelMapContourOverlayImageFilter.hxx | Corrects the contour thickness remapping to skip the selected slice dimension. |
| Modules/Filtering/LabelMap/include/itkAttributeUniqueLabelMapFilter.hxx | Runs the removal pass for label objects that become empty during uniqueness filtering. |
| Modules/Filtering/LabelMap/include/itkLabelMap.hxx | Adds explicit free-label tracking before adding a pushed label object. |
| Modules/Filtering/LabelMap/include/itkLabelMapMaskImageFilter.hxx | Builds a zero-size crop region when no object lines contribute to the crop box. |
| Modules/Filtering/LabelMap/include/itkMergeLabelMapFilter.hxx | Scopes deferred collision objects to each input during keep-mode merging. |
| Modules/Filtering/LabelMap/include/itkStatisticsLabelMapFilter.hxx | Matches weighted shape ratio handling to the clamped principal moment behavior. |
| Modules/Filtering/LabelMap/test/CMakeLists.txt | Registers the new LabelMap bugfix test source. |
| Modules/Filtering/LabelMap/test/itkLabelMapBugfixGTest.cxx | Adds regression tests for full label ranges, signed weighted shape metrics, and emptied unique-label objects. |
Reviews (3): Last reviewed commit: "BUG: Clamp weighted moments in Statistic..." | Re-trigger Greptile
Member
Author
|
@greptileai review this draft before I make it official |
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.
Fixes six LabelMap / label-statistics correctness bugs catalogued in #6575 (items B40–B45): one
BUG:commit per item. All in-memory logic, no fixtures; three items ship dedicated fail-before/pass-after GoogleTests and the rest are covered by the module regression (136/136 local).Per-item summary
MergeLabelMapFilter(KEEP)LabelMapContourOverlayImageFilter(SLICE_CONTOUR)jagainstSliceDimensionwhere it meant the read indexi;SliceDimension == 0left the radius all-zero and drew no contour. Test the read index.LabelMapMaskImageFilter(Crop)maxs - mins + 1overflowed (UB) and the filter allocated a 2×2 image at index 2⁶³−1. Use an empty region when no lines are found (both crop sites).AttributeUniqueLabelMapFilterwhile (it.IsAtEnd())) and never ran, so an object whose pixels were all claimed by a higher-priority object survived with zero lines (and fed the B42 crop path).LabelMap::PushLabelObjectlabel == lastLabel) never held, soAddLabelObjectsilently overwrote the object's own entry. Track whether a free label was found and throw otherwise.StatisticsLabelMapFilterShapeLabelMapFilterreturns 0. Clamp the moments and guard each ratio, matchingShapeLabelMapFilter.Testing
New
itkLabelMapBugfixGTest.cxxadds three tests, each verified to fail on the unfixed tree and pass after:PushLabelObjectthrow (silently overwrote before).B40/B41/B42 are covered by the existing ITKLabelMap + ITKImageFusion regression (136/136 pass locally); dedicated fail-before tests for those can be added on request.
pre-commit run --all-filesis clean.Findings and analysis by the #6575 reporter; see that ledger for the full derivations.