Repository navigation
Correct adaptive threshold windows for narrow regions and borders - #3229
Merged
JimBobSquarePants merged 2 commits intoOct 27, 2026
Merged
JimBobSquarePants merged 2 commits into
JimBobSquarePants merged 2 commits into
Conversation
…n 16 pixels The cluster size is the region width divided by 16, truncated, so it was 0 for regions narrower than 16 pixels. Every averaging window was then empty and each pixel took the lower color. Use a cluster size of at least 1, as regions 16 to 31 pixels wide already do. Wider regions are unchanged.
4 tasks done
Include the current pixel and both window endpoints when querying the inclusive integral image. Reuse integral row spans and hoist vertical bounds out of the pixel loop. Check all border pixels and single-pixel dimensions against direct neighborhood sums. Independent direct summation reproduced every old reference with the old shifted windows and matched every corrected output with centered windows. Update those five proven incorrect references; exact comparisons remain unchanged.
4 tasks done
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.
Prerequisites
Description
Adaptive thresholding can produce an empty window for narrow regions and borders. The integral-image query also shifts the window away from the current pixel. Empty windows always select the lower color.
The window now stays centered on the current pixel and includes both endpoints. Its bounds are clipped to the processing rectangle. The sum and pixel count use those same inclusive bounds, including for one-pixel dimensions. The existing radius cap, bulk luminance conversion, integral-image allocation and parallel row iterator remain in use. Integral row spans are acquired once per output row.
The tests check every pixel, including borders. A separate direct-sum calculation checks centered windows, single-pixel dimensions, the radius transition, non-origin rectangles and unchanged pixels outside the rectangle. All 12 regression cases fail on the original PR and pass with this correction.
Five old reference images were independently checked before updating them. Direct neighborhood summation reproduced every old reference with the old shifted windows and matched every corrected output with centered windows. The changed pixel counts are 181 for Bradley01, 579 for Bradley02, 90 for Ducky, 55 for Issue2217 and 20 for the Bradley02 rectangle. Exact comparisons remain unchanged.
Verification
Release, .NET 10: 127 passed, 0 failed, 0 skipped for binarization and integral-image tests.
Fixes #3241