Repository navigation
fix: keep the plateau rule and the full-resolution fine sweep in SkewCorrector - #21
Merged
Merged
Conversation
…Corrector Making the corrector faster (ispras#20) lost two things the previous implementation relied on, and a document with short lines now comes back rotated by 1 degree: dedoc's test_module_skew_corrector fails on all five short_lines images. - The projection score of such a document has a plateau, not a peak. The old sweep resolved it: if the score two steps away is within 2% of the maximum, the angle between them wins. Restored on the fine sweep. - The fine sweep ran on an image downscaled to 1000px, which is enough to shift a borderline 1-degree decision. It runs on the thresholded image again; only the coarse guess keeps its 512px thumbnail, which is where the speed comes from. On the 31 images of dedoc's tests/data the corrector now returns the same angle as 0.3.8 on all of them (it differed on 5 + 2 of them before), and stays 8.3x faster than 0.3.8 (22.8s -> 2.7s over that set).
NastyBoget
self-requested a review
September 8, 2026 08:10
NastyBoget
approved these changes
Sep 8, 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.
After #20 a document with short lines comes back rotated by one degree: dedoc's
test_module_skew_corrector.test_documents_with_short_linesfails on all fiveshort_lines-*.pngimages (0 != 1.0). The failing test is the visible part — on dedoc's testimages the angle changed on 9 of 31,
bold_font.png,orient_4.png,scan_orient_1.jpgandexample_with_table5.pngamong them.Two things the previous implementation relied on were lost, and it takes both of them to get the
old answers back.
The plateau rule. The projection score of a document with short lines has a plateau rather
than a peak. The old sweep resolved it: if the score two steps away is within 2% of the maximum,
the angle between the two wins. Restored on the fine sweep.
The fine sweep ran on a downscaled image. 1000px on the long side is enough to flip a
borderline one-degree decision. It runs on the thresholded image again; the coarse guess keeps its
512px thumbnail, which is where the speed comes from.
Measured
Angles compared against 0.3.8 on the 31 images of dedoc's
tests/data:So the corrector agrees with 0.3.8 on every image again, and stays 6.4x faster than it
(~0.11 s per page against ~1.0 s; 0.3.10 was ~0.06 s).
tests/unit_tests/test_preprocessors.pypasses unchanged,flake8 .is clean, and dedoc'stest_module_skew_correctorpasses against this build.