Page 1 of 2

Automatic page rotation

Posted: Wed Aug 06, 2008 8:09 am
by Peter
I have a scanner without this function in its twain software. Anyone experience with a program or photoshop script / plugin that aligns your score perfectly horizontal? Now I do this by placing the measure tool on a score line after which I manually rotate the page, the angle of which is automatically filled in by the measure tool. Recording these actions in a macro does not work, as the value of rotation is also stored in the macro.

Posted: Wed Aug 06, 2008 6:30 pm
by carmar1791
In acrobatprofessional if you apply recognition of document (text) it do all this automaticly.
On linux gscan2pdf can deskew and allign border.(Its difficult to use).
This what I know.Usually I do always manually(gimp)
Ciao

Carmar

Posted: Wed Aug 06, 2008 7:46 pm
by Peter
Thank you. That's a possible solution. It would be ideal of course if it would work in photoshop so that all editing (monotoning, border removal, etc) could be run in one batch.

Posted: Wed Aug 06, 2008 8:36 pm
by daphnis
Peter, I create custom droplets in Photoshop that allow me to rotate any image by an arbitrary amount. I then save that so I can access it with a single click or keystroke. Even though you have to gauge the amount of rotation by eye, you can create a droplet/macro that will convert the image, rotate by x amount, then convert back. For example, if I wanted to rotate a certain image by 1 degree counter clock, I'll record a droplet using the arbitrary rotation function and save it.

Posted: Wed Aug 06, 2008 8:41 pm
by Peter
Thanks. The problem is I always turn up placing books skewed very differently on my small scanner so a fixed rotation angle won't get them right. Making a collection of macros with different angles would be an alternative, but guessing the angle by the eye for each page gives at the end (for me) probably more work than quickly placing a line with the measure tool.

As most OCR programs can do it, there's got to exist some photoshop plugin...

Posted: Wed Aug 06, 2008 8:53 pm
by daphnis
Peter, I guess it depends the margin of rotation skew on your images. Mine usually never go beyond 2 degrees, so I usually have macros from 0.5 degrees up to 1.5 degrees. These macros make quick work of each image as I can usually get the image at the correct adjustment within 0.2 degrees. Another thing that may be worth mentioning if you're concerned about printing: Acrobat reader and professional both have skew adjustments when printing, which can correct some really bad rotations in my experience, even a slight amount left over after manual rotation.

Posted: Thu Aug 07, 2008 4:04 am
by Carolus
One of the things you will run into with printed scores, especially ones that have been reissued many times over, is the absolutely horrendous practice of some publishers or printers who simply take a bound copy from the previous run and place it beneath the printer camera. (They can sell that copy after the picture has been taken and the new "plates" burned!)

This results in a characteristic curvature found on the right end of even-numbered pages and the left end of odd-numbered ones. Repeat the process a few times, add some skewing generated by scanning and...voila! You end up with quite a fun-house mirror image of a music score. Recent Hal Leonard printings of the Mozart Requiem vocal score (itself a reprint of the Peters vocal score form ca.1880) are really quite remarkable in this regard. One could easily spend 2-3 hours per page in Photoshop fixing such atrocities. It's not worth the effort. GI/GO.

Lesson: Try to find a decent printing to start with. Not always easy to do, but it definitely improves the quality of the final product.

Posted: Sun Sep 14, 2008 5:24 am
by horndude77
I've been messing with this lately. Here are some things I've found:

Gimp plugin: http://www.cubewano.org/gimp-deskew-plugin/
I've been using this recently and it works quite well.

Unpaper: http://unpaper.berlios.de/
I haven't totally figured out how to make this work. Besides deskewing, it does some other nice things to clean up the image (remove noise pixels, black border, etc.) Unfortunately with one of my tests I couldn't get it to correctly rotate the page (though it did do some good clean up to the page), and with another test it didn't correctly convert grayscale to black and white. I still need to mess with it some more.

The technical term for what Carolus was referring to is 'dewarping'. There are some good algorithms for fixing it, but I don't know of any readymade plugins. Most are also targeted towards text documents so I'm not sure how well music will fare. Here's an online example program: http://quito.informatik.uni-kl.de/dewarp/dewarp.php.

Posted: Sun Sep 14, 2008 9:34 am
by Peter
That is a most interesting program. Thanks

Posted: Mon Sep 15, 2008 12:37 am
by daphnis
@horndude

Do you have a pre-compiled win32 binary of unpaper 0.3?

Posted: Mon Sep 15, 2008 1:19 am
by horndude77
Here's one I just built: http://horndude77.googlepages.com/unpaper.exe

I'll take this down in the next day or so. I haven't tested it beyond 'unpaper --version'.

I built with mingw:
https://sourceforge.net/project/showfil ... _id=240780

Once mingw was installed I ran this from the src directory:

>gcc unpaper.c -o unpaper.exe -I "C:\mingw\include" -L "c:\mingw\lib"

If you figure out some good options let us know.

I heard about the tool reading over at the distributed proofreaders forum: http://www.pgdp.net/phpBB2/viewtopic.php?t=18964

Posted: Mon Sep 15, 2008 1:28 am
by daphnis
For some reason my MinGW is acting sick. I also tried working with gscan2pdf as a frontend, which may prove useful, but I couldn't get latest version compiled. Ubuntu package manager only had .21 I think, and even then unpaper refused to process my one test image.

When using this win32 bin I get the same error as in *nix:
"input file format using magic 'II' unknown

Posted: Wed Sep 17, 2008 2:27 am
by horndude77
You're trying to use a tiff file (magic number "II*."). Unpaper requires a pgm, pbm, or ppm. Unfortunately you do lose dpi information so when converting back to tiff that'll have to be added back in.

Posted: Wed Sep 17, 2008 2:42 am
by daphnis
Yeah I figured that out after I posted it and have been playing with it. I'm having difficulties with the masks obliterating my instrument abbreviations sometimes, and others pages that were somewhat straight now skewed. I contacted the author but haven't heard anything back yet. I'm not sure how to configure it best for music and was hoping for his input. When it works it does a really nice job. I just need to figure out how I can write back the dpi info. in a batch convert from PBM->TIFF.

Posted: Wed Sep 17, 2008 3:20 am
by horndude77
Something like this should do the trick (using imagemagick and bash):

Code: Select all

#!/bin/bash
for i in *.pbm
do
  convert -density 600 -units PixelsPerInch $i ${i%.*}.tiff
done