Automatic page rotation

Advice and Help

Moderator: kcleung

horndude77
active poster
Posts: 293
Joined: Sun Apr 23, 2006 5:08 am
notabot: YES
notabot2: Bot
Location: Phoenix, AZ

Post by horndude77 »

...and others pages that were somewhat straight now skewed
I don't think unpaper's deskew method works very well with music. However http://pagetools.sourceforge.net/ seems to work nicely at finding the skew angle.

Here's a script I just made to deskew a grayscale tiff using tiff_findskew and convert. It could be easily adjusted to work directly on b&w scans also. Perhaps unpaper could be used after this for further clean up.

Code: Select all

#!/bin/bash
PAGE_TOOLS_BIN=./
TIFF_FILE=$1
TIFF_BW_FILE=${TIFF_FILE%.*}-bw.tiff
TIFF_DESKEWED_FILE=${TIFF_FILE%.*}-deskew.tiff

#tiff_findskew require a monochrome image.
convert $TIFF_FILE -monochrome -compress Group4 $TIFF_BW_FILE
SKEW=`$PAGE_TOOLS_BIN/tiff_findskew $TIFF_BW_FILE`
#Negate the skew to correct it.
SKEW=`echo " - $SKEW" | bc`

#perform the rotation
convert $TIFF_FILE -distort SRT "0,0 1.0 $SKEW 0,0" $TIFF_DESKEWED_FILE
daphnis
Copyright Reviewer
Posts: 1634
Joined: Thu May 17, 2007 7:15 pm
notabot: 42
notabot2: Human

Post by daphnis »

Cool. Can you post a win32 binary? This might be a good idea, but for most practical cases the script/app would be run on 1-bit images. Problem with unpaper is the code is slow on 1-bit images even disabling grayfilter and blurfilter.
horndude77
active poster
Posts: 293
Joined: Sun Apr 23, 2006 5:08 am
notabot: YES
notabot2: Bot
Location: Phoenix, AZ

Post by horndude77 »

http://horndude77.googlepages.com/tiff_findskew.exe

I built this with cygwin so you'll have to run it from cygwin. Make sure you install libnetpbm and libtiff.

It's actually pretty easy to build. There's one line to comment out in the makefile for libnetpbm which is clearly marked.
Post Reply