Repository navigation
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
This branch has not been deployed
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
Problem.
AdaptiveThresholdProcessorsets the cluster size to the processed region's width divided by 16, truncated. For a region narrower than 16 pixels, the cluster size is 0. The averaging window is the integral-image range(x1, x2] x (y1, y2], and with a cluster size of 0 every window is empty (count == 0). The comparisonluminance * 0 <= sum * limitis then always true, so every pixel takes the lower color. For example, a light 8x8 image with one dark pixel comes out all black. The same happens when a narrow rectangle is passed toAdaptiveThreshold(upper, lower, rectangle).Change. The cluster size now has a minimum of 1, so regions narrower than 16 pixels use the same window as regions 16 to 31 pixels wide. Regions 16 pixels and wider get the same cluster size as before, so their output does not change. All existing exact-match reference outputs still pass.
Known limitation (not changed). When the cluster size is 1, the window for the last column and the last row is still empty, so those pixels always take the lower color. Regions 16 to 31 pixels wide already behave this way. The 30x30
Issue_2217exact reference output depends on this behavior, so changing it would mean regenerating that reference image. A region only 1 pixel wide or tall also still gets an empty window.Testing.
AdaptiveThresholdTests:AdaptiveThreshold_NarrowImage_SeparatesDarkPixel(3x3, 8x8, 15x15, 15x3) andAdaptiveThreshold_NarrowRectangle_SeparatesDarkPixel(an 8x50 rectangle in a 100x100 image). Each test fills the region with a light color, adds one dark pixel, and checks that only the dark pixel turns black. All five cases fail without the fix and pass with it.Processing,DrawingandImageTestsnamespaces, 1595 passed, 2 were skipped and 1 failed. The failure wasImageTests.SaveAsync.SetEncoding, anIOExceptionbecauseImageTests.Save.SetEncodingwas writing the sameSetEncoding.datoutput file at the same time. Both tests pass when run on their own, and this change does not touch that code.Fixes #3241