Repository navigation
BUG: Fix anchor morphology for nearly equal floats and thin regions - #7256
Conversation
AnchorErodeDilateLine::Compare is the non-strict form of TCompare. Math::AlmostEquals let a float neighbor a few ULPs on the wrong side replace the running extreme, so anchor dilation could return less than the input pixel. ClosingByReconstructionImageFilter then threw "Marker pixels must be <= mask pixels." on float images.
Reconstruction by erosion requires marker >= mask, and by dilation marker <= mask; the messages stated the opposite.
MakeEnlargedFace identified each face's normal as its size-1 dimension. For a region with size 1 along another dimension, no face matched the line, so anchor and van Herk/Gil-Werman erode/dilate/open/close left the output unwritten. Such regions come from thin images and from per-thread regions when the kernel radius is 0 along the split axis.
|
@greptileai review this |
[Medium impact] The PR appears safe to merge; no actionable defects were found.
|
hjmjohnson
left a comment
There was a problem hiding this comment.
Thanks, @dzenanz. I reviewed all three commits and checked them locally; I found nothing blocking. All comments below are nits.
- Tests: on macOS with clang (Release build), the 6 new GTests pass at
31d5187e9cb. With the base versions ofitkAnchorErodeDilateLine.h,itkReconstructionImageFilter.hxx, anditkSharedMorphologyUtilities.hxxand the same tests, all 6 fail, each for the reason its commit message gives:- dilation lands a few ULPs below the input, for example
49.9999962vs50; ClosingByReconstructionthrows;- the degenerate-region outputs differ from BASIC;
- the precondition message is inverted.
- dilation lands a few ULPs below the input, for example
- Face selection: for regions with every dimension > 1, the new
MakeEnlargedFacepicks the same face asNeedToDoFacedid. That holds for diagonal and negative line directions too, so normal output is unchanged. All four callers (anchor erode/dilate, anchor open/close, and vHGW) go through it. - Reconstruction: the comparison logic was already right, and the messages now match it for both erosion and dilation.
Nits:
NeedToDoFace(itkSharedMorphologyUtilities.h:28) now has no callers in the tree. Since it is public, keep it or deprecate it, as you prefer.<list>is still included in the.h.!compare(b, a)is true when either value is NaN, while the oldcompare || AlmostEqualswas false. That is unlikely to matter, but one clause in the commit 1 body would record it.
|
|
||
| typename TInputImage::RegionType RelevantRegion; | ||
| for (; fit != faceList.end(); ++fit) | ||
| // Select the face by DomDir, not by a size of 1: AllImage itself may have size 1 along other dimensions. |
There was a problem hiding this comment.
nit: comments should describe the code as it is, not the approach it replaced.
| // Select the face by DomDir, not by a size of 1: AllImage itself may have size 1 along other dimensions. | |
| // AllImage may have size 1 along dimensions other than DomDir. |
| break; | ||
| } | ||
| } | ||
| const unsigned int NonFaceDim = DomDir; |
There was a problem hiding this comment.
nit: NonFaceDim is only an alias for DomDir now; using DomDir directly in the lines below would read more plainly.
| auto filter = TFilter::New(); | ||
| filter->SetInput(input); | ||
| filter->SetKernel(KernelType::Box(radius)); | ||
| filter->SetAlgorithm(algorithm); |
There was a problem hiding this comment.
nit: the {16,3} / radius {1,0} case reaches 1-row per-thread regions only when the default work-unit count splits the image, so it depends on the runner's core count or ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS. Pinning it makes the per-thread case deterministic (the 16x1 and 1x16 cases already cover thin images on every runner):
| filter->SetAlgorithm(algorithm); | |
| filter->SetAlgorithm(algorithm); | |
| filter->SetNumberOfWorkUnits(3); |
Set the global default to 3 threads while constructing each filter, so the 16x3 image always splits into 1-row per-thread regions. Composite filters such as GrayscaleMorphologicalOpeningImageFilter construct their inner filters with that default, so SetNumberOfWorkUnits on the outer filter would not reach them. The test no longer depends on the core count or ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS. Also use DomDir directly in MakeEnlargedFace instead of its NonFaceDim alias, and reword a comment to describe the current code. Follow-up to review of InsightSoftwareConsortium#7256.
Anchor and van Herk/Gil-Werman morphology: exact float comparison (float dilation could fall below the input, making
ClosingByReconstructionImageFilterthrow), and correct output for regions 1 pixel thick. Also fixes inverted reconstruction precondition messages.AI assistance
Claude Code (Claude Opus 5.5): root-cause analysis, fixes, and regression GTests. Tested locally with MathematicalMorphology, BinaryMathematicalMorphology, and LabelMap tests.
🤖 Generated with Claude Code