How to automatically straighten a scanned document in Debian Linux, undoing a possible rotation of the text?
13
votes
2
answers
1106
views
Consider the image
(the sensitive header and footer have been blanked for the purpose of this question, which would be valid also with them). As you see, it's a bit tilted clockwise. We tried to straighten it via

$ pngtopam test.png > test.pgm
$ rm -f test_unpaper.pgm && dpi=600 && unpaper -start 1 -end 1 --dpi $dpi -dr 10 -dp 0.01 -dv 10 -v test.pgm test_unpaper.pgm
…
detected rotation left: [235,0,4795,7015]: 0.000000
detected rotation right: [235,0,4795,7015]: 0.000000
rotation average: 0.000000 deviation: 0.000000 rotation-scan-deviation (maximum): 0.174533 [235,0,4795,7015]
rotate (2550,3508): 0.000000
…
We tried to play with the switches -dr
and -dp
; without them, the result is equally bad: the output is tilted in any case. Any improvement? Ideally, we'd like to get a straightened image automatically, without caring about switches; in particular, the effort should be less than for a precise manual rotation in GIMP. (An aside: for the purpose of this question, nothing else is needed: no denoising, no sharpening, no margin removal or image centering, ….).
Asked by user743115
(1 rep)
May 19, 2025, 06:15 AM
Last activity: Jul 27, 2025, 02:42 PM
Last activity: Jul 27, 2025, 02:42 PM