How to make a rectangular object perfectly square using the panotools:

The frame is straight, but somehow the photo looks distorted.


The camera (film/sensor) was not exactly parallel to the object during the exposure and resulted in a slightly skewed frame along with some distortions (bowed lines) caused by the lens:


This can easily be fixed with the panotools: start with vertical and horizontal control points. For this I'm using the PTGui software. Note: by default t1 points (vertical line) are selected. Change horizontal control points to the t2 type.


It is important to align vertical and horizontal control points not only at the corner points but also in the middle of the sides. Any camera lens has a distortion and lines are not straight. Using the middle points will fix those bows too.


Make sure the lens type is rectilinear:


And the projection is set to rectilinear:


Select Raw, Pitch and Roll and run the first optimization. It is important not to select all variables at once: optimization is finding a low spot in a multidimensional field and optimizing for Raw, Pitch and Roll first you make sure not to optimize on a local spot in a wrong location.


The first result looks good and corners are aligned correctly. Now we fix the bowed lines.


Add the Field of View, b and vert/horz shift. Do not use a, b and c altogether. Just the b parameter is perfectly suited for the non-wavy camera lens distortions. The optimizer can now calculate the exact parameter values:


The object is now straitened:


The panotools take all the calculated parameters and create the final output image:


Perfectly square: