Page 1 of 1

How to unwarp a page gutter?

Posted: 2015-11-13T09:02:39-07:00
by nicolai.rostov
I'd like to straighten out photos taken from book pages. For example, page (image #1) is mostly, but not entirely, warped toward the book gutter. The difficulty is that each line bottom-up is more deeply warped than the line right below it (image #2), and the shrink factor increases left to right, so that a perspective correction will not do.

I was trying to distort it using the shepards method but the resulting image (#3) was coming out even more distorted than the original.

Code: Select all

convert <input> -distort Shepards '15,45 15,45 ...' <output>
I need another approach. What would be a more efficient way to achieve this?

Thank you.


image 1
Image

image 3
Image

image 3
Image

Re: How to unwarp a page gutter?

Posted: 2015-11-13T11:02:46-07:00
by snibgo
There is displacement in both directions. The letters in the gutter are displaced down and to the left. The right side of the page approximates to a cylinder, photographed by a camera. Fred and I have pages on transforming cylinders to planes. My page considers only parallel projection, where the camera is at infinity, so would need adjustment because your camera is clearly closer. Modulating the y-displacement by the height above the bottom would be good first-try.

Re: How to unwarp a page gutter?

Posted: 2015-11-13T13:43:05-07:00
by nicolai.rostov
Okay. I'm trying to understand how Fred's pinbarrel works but am clueless as to how to calculate the right radial distortion/correction coefficients.

There is an example on Fred's homepage to make a square into an image which is distorted in a way that looks like my page above. I'd like to build from that into a solution to my problem. Here is Fred's code:

Code: Select all

pinbarrel "0.5,0.5,0,0,0" -c 64,64 infile outfile
Image

How can I determine the argument to achive the opposite effect? How does one determine the radial coefficients and center point coordinates?

Re: How to unwarp a page gutter?

Posted: 2015-11-13T13:54:56-07:00
by fmw42
IM has this implemented, though I do not think it will be relevant to what you want. See http://www.imagemagick.org/Usage/distorts/#barrel. But there is no way to compute the exact values you would need, as far as I know.

Re: How to unwarp a page gutter?

Posted: 2015-11-13T14:10:29-07:00
by nicolai.rostov
Thanks. Is it possible to apply an (inverted) IM's barrel distortion method diagonally? All examples on that page are distorted around a vertical or horizontal axis in the middle of the image.

Re: How to unwarp a page gutter?

Posted: 2015-11-13T14:22:32-07:00
by snibgo
Barrel (and pincushion) distortion move pixels towards (or away) from a centre. You don't have that distortion. We know that because the top edge has a curve, but none of the others do.

Open a book, and look at how the paper is curved near the gutter. It is curved in one direction only, like part of a cylinder.

Re: How to unwarp a page gutter?

Posted: 2015-11-14T05:39:42-07:00
by nicolai.rostov
I see. But is there any way to apply a pincushion distortion only to the right side of an image, though? Or maybe I could rotate the original so that the current distortion axis (white-gray boundary above) goes to the center of the image, and then apply a pincushion distortion to that, crop the right-hand side off, lay it over the original rotated image, and rotate everything back to the original position.

At any rate how do people go about determining the multiple radial coefficients and center point coordinates of a pincushion distortion? It can't be by trial and error only. I think I understand how the Shepards method works but I am clueless regarding barrel and pincushion. A small change to any of those coefficients results in a completely different image.