# How to align a poster?

I'd like to crop and transform out the magazine cover so that it is rectangular.

I read the docs for ImagePerspectiveTransformation, and here's where I got to. First, I found the bounding polygon top-left top-right, bottom-right and bottom-left points:

img = Import@
"http://www.vinylbanner.com/media/catalog/product/cache/1/image/\
1800x/040ec09b1e35df139433887a97daa66f/s/l/slanted-magic-mount-3.jpg";
corners = {{212.29296875, 156.265625}, {594.69921875,
157.5703125}, {489.16796875, 424.98828125}, {236.30859375, 430.54296875}};


Assuming its aspect ratio is 11 by 8.5 and it is 100 pixels tall:

h = 100;
w = (8.5/11)*h;
ft = FindGeometricTransform[corners, {{0, h}, {w, h}, {0, w}, {0, 0}}]
new = ImagePerspectiveTransformation[img, ft[[2]]]


but I get an error:

• Are you sure those corners are coordinates? They more like RGB values. – Niki Estner Sep 12 '16 at 5:49
• Yup, sorry bout that, fixed! – user5601 Sep 12 '16 at 5:51

A few minor mistakes:

• corners and the target coordinates weren't in the same order
• For some reasons, pixels isn't the default unit for ImagePerspectiveTransformation and friends - you have to specify PlotRange and DataRange explicitly
• the target coordinates should go first in FindGeometricTransform - alternatively, you can pass InverseFunction@ft[[2]] to ImagePerspectiveTransformation

h = 300;