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:
Answer
A few minor mistakes:
cornersand the target coordinates weren't in the same order- For some reasons, pixels isn't the default unit for
ImagePerspectiveTransformationand friends - you have to specifyPlotRangeandDataRangeexplicitly - the target coordinates should go first in
FindGeometricTransform- alternatively, you can passInverseFunction@ft[[2]]toImagePerspectiveTransformation
Which leads to this result:
h = 300;
w = (8.5/11)*h;
ft = FindGeometricTransform[{{0, 0}, {w, 0}, {w, h}, {0, h}}, corners]
new = ImagePerspectiveTransformation[img, ft[[2]],
PlotRange -> {{0, w}, {0, h}}, DataRange -> Full]



Comments
Post a Comment