Skip to content

fix: keep the plateau rule and the full-resolution fine sweep in SkewCorrector - #21

Merged
NastyBoget merged 1 commit into
ispras:masterfrom
OligerMan:fix/skew-plateau
Sep 8, 2026
Merged

NastyBoget merged 1 commit into
ispras:masterfrom
OligerMan:fix/skew-plateau

Conversation

@OligerMan

Copy link
Copy Markdown
Collaborator

After #20 a document with short lines comes back rotated by one degree: dedoc's
test_module_skew_corrector.test_documents_with_short_lines fails on all five
short_lines-*.png images (0 != 1.0). The failing test is the visible part — on dedoc's test
images the angle changed on 9 of 31, bold_font.png, orient_4.png, scan_orient_1.jpg and
example_with_table5.png among 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:

build same angle as 0.3.8 short_lines-*.png time, all 31
0.3.8 31 / 31 5 / 5 22.5 s
0.3.10 22 / 31 0 / 5 2.6 s
0.3.10 + plateau rule only 29 / 31 5 / 5 2.6 s
0.3.10 + full-resolution fine sweep only 27 / 31 2 / 5 3.7 s
this PR (both) 31 / 31 5 / 5 3.5 s

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.py passes unchanged, flake8 . is clean, and dedoc's
test_module_skew_corrector passes against this build.

…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
NastyBoget merged commit fe70c23 into ispras:master Sep 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants