Page 1 of 1

Automatically correcting trapezoidal distortion

Posted: 2014-02-18T10:52:20-07:00
by aporthog
I am about to write a program to automatically detect and correct trapezoidal distortion of book pages and thought I'd run it by you guys to see if you had any suggestions to make the task easier or faster. I've had good luck in a test program I made using certain assumptions that i can't make for more generic cases. Now i want to make it more robust and generic so my plan is to detect the 4 white corners of the page before any deskew, and then undistort them to make the left and right pages edges equal sizes. I know how to do this. So my questions are:

1. I will use txt:- info to loop through 4 approximate parts of the image until I locate the 4 white corners. The cropping you see in the example and the width of the black areas are approximately the same for every single image so no need to go hunting through the entire image for the corners, only need to root around four general areas. This is a time consuming operation and rather complicated to write. I can make certain shortcuts by reducing the image dimensions significantly but can't reduce too far or risk losing precision. Is there a clever or faster way to locate these corners? I'm tempted to use morphology somehow but I'm not sure how the slight distortion of the corners could throw that off - they're not exactly right angles.

2. Do you think it's better to lengthen the shorter side to match the longer and introduce virtual pixels or reduce the longer side and eliminate pixels?

3. Is there an automatic detrapezoidify command in ImageMagick? Hey, it can't hurt to ask! :)

Image

Full-size image: http://ucblibrary4.berkeley.edu/~apollo ... torted.jpg

Thanks all!

Re: Automatically correcting trapezoidal distortion

Posted: 2014-02-18T11:00:31-07:00
by fmw42
If on Linux or Mac (or Windows with Cygwin), try my script, unperspective, at the link below. Otherwise, you can use -distort perspective but you need to pick control points manually.

Re: Automatically correcting trapezoidal distortion

Posted: 2014-02-18T12:05:06-07:00
by aporthog
I will try and sort through that. We're on Windows and Solaris but the Solaris IM is too old and we haven't been able to compile a new version. I'll try and find the salient points and convert them to perl and add them to my module. I'm trying to understand the idea of finding the peaks and the whole conversion between cartesian and polar. If I can get a handle on what's going on there I should be able to handle the rest myself.

Thanks!