Important: the Perspective transform cannot guess the actual aspect ratio of the original image, so the result can require being re-scaled in one direction using “out-of-band” data (for instance if you now that the original sheet of paper is Letter or A4, or that some vertical and horizontal parts of the image should have specific length ratios).