Unix utility that straightens images?
February 8, 2006 8:26 AM   Subscribe

Is there a Unix command-line utility that automatically straightens images?

I have some images containing pure black text on a white background, but these images were scanned from paper documents and aren't aligned perfectly -- that is, the text is slightly on an angle. I'd like to find a Unix tool that automatically rotates the images so that the text is straight.

(The Unix part is important, as this process will be automated on a Linux box. And I'm dealing with hundreds of images here, so I don't have the resources to do the rotation by hand.)

The images contain only text, no graphics. The rotation needed is inconsistent across documents, but it's generally between .5 and 2 degrees in either direction.
posted by adrian_h to Computers & Internet (6 answers total)
 
Well, I'd start with imagemagick.
convert -rotate nn foo.jpg foo_rotated.jpg
posted by boo_radley at 8:45 AM on February 8, 2006


The ImageMagick "convert" program can do rotations. But you have to tell it by how much. I'm no unix guru, but I expect there's no off-the-shelf package to do this.

If you could find a package which could tell you the rotation you could do it (by finding the required rotational degree and then calling convert) but I'd be surprised if such a beast existed. What you're looking for is something that fits lines to an image, and tells you their orientation.

Disclaimer: I'm a CV researcher but I've never done much text processing so I could be wrong here.
posted by handee at 8:49 AM on February 8, 2006


I've posted too soon. The difficult part will be figuring out how to programmatically address inconsistent rotation. I can't think of a good way to do that part offhand.
posted by boo_radley at 8:50 AM on February 8, 2006


You probably want a program that can do OCR.

This one looks like it does pre-processing to align the documents properly. It may be possible to skip the OCR process and just have it align the images.
posted by empath at 8:55 AM on February 8, 2006


Best answer: I know what you are looking for exists, adrian -- back in the early 90s we used such software at my shop here frighteningly, on a PC via primtive UNIX emulation tools -- yikes!. That was sadly some time ago and I don't know that anyone could remember what the hell it was we used though "imgfix" comes to mind (google is a bit unhelpful here). The tool was designed to correct the "skew" on auto-fed scanners which at the time were quite teh-sucky, but I'm sure the problem continues with hand-scanned docs today.

quick googlesmack provides this link which might be a bit rough-and-ready, but might serve a batch process. Uses PGM files.

unpaper looks pretty cool in both auto deskewing and fixing a number of other paper-conversion issues. Uses PBM files.

Imagemagic's afformentioned `convert` will help ease the translation pain.
posted by Ogre Lawless at 12:37 PM on February 8, 2006


Response by poster: Ogre Lawless: Thanks very much! Those two tools look like exactly what I needed.
posted by adrian_h at 1:04 PM on February 8, 2006


« Older Help Me Get Married in Alameda County   |   Wedding tipping etiquette Newer »
This thread is closed to new comments.