Keystone Distortion and How to Undo It

Point a camera up at a building and the walls lean inward. Photograph a page on a desk from where you are sitting and the far edge is shorter than the near one. Neither is a lens fault, and neither can be fixed by rotating the image. It is keystone distortion, and undoing it needs a different kind of transform - the one behind our perspective corrector.

Why parallel lines stop being parallel

A camera projects the three-dimensional world onto a flat sensor. In that projection, parallel lines in the scene converge toward a vanishing point unless they happen to run parallel to the sensor plane. So the rule is simple: if the sensor is parallel to the surface you are photographing, the surface's edges stay parallel in the image. Tilt the camera, and they converge.

That is why the effect shows up in two everyday situations. Tilting up to fit a tall building into the frame makes verticals converge toward the top, so the building appears to fall away from you. Photographing a document from a seated position means the sensor is tilted relative to the page, so the rectangle becomes a trapezoid - wider at the near edge, narrower at the far one. The name comes from that trapezoid, which is the shape of an architectural keystone.

Rotation cannot help, because rotation is rigid: it moves the whole frame without changing the relationship between its parts. Undoing convergence needs a transform that can move each corner independently, stretching one part of the image more than another. That is a homography, or perspective warp, and it is defined by exactly four point correspondences - which is why the tool gives you four draggable corner handles and nothing else.

Documents: the flatbed scanner you already own

This is the highest-value use. A phone photo of a receipt, a contract, a whiteboard, a page from a library book, or a form you need to email is almost always shot at an angle, and the result looks casual and reads badly. Dragging the four handles onto the corners of the page and applying the warp produces something close to a scan: square margins, straight text lines, no trapezoid.

A few things that make the result better:

Buildings, interiors, and artwork

For architecture, the goal is usually verticals that actually run vertical. Place the handles on identifiable corners of the facade - the top and bottom of two window columns on opposite sides works well - and correct until the sides are plumb. Two cautions. First, fully correcting a strongly upward shot can leave the building looking top-heavy, because we are used to seeing a little convergence; correcting most of the way rather than all of the way often looks more natural. Second, interiors have many competing planes, so decide which surface you are straightening and accept that others will shift. Photographing framed artwork or a plaque on a wall is the easy case, since the object is a clean rectangle with high-contrast corners.

What correction costs you

A perspective warp resamples the image, which is not free:

The mitigation is all in capture: get closer to square-on and there is less to undo. If you can shoot a document from directly above rather than at 45 degrees, the correction becomes a small nudge rather than a heavy stretch, and the output keeps far more real detail.

Why doing this locally matters

Look at the list of things people straighten: contracts, invoices, ID cards, medical forms, tax paperwork, whiteboards full of unreleased plans. That is close to a worst-case set of documents to upload to an unknown web service. The corrector reads your file with the browser's local file API, draws the warped result to a canvas in the page, and downloads it from there. No upload step exists in the tool, so there is nothing to opt out of.

Related reading

Straighten before you crop, then see aspect ratios and composition for trimming the corrected frame, and JPG vs PNG vs WebP for exporting a document scan at the right format. Everything else is on the Privacy Pix Tools blog.

Straighten Image

Fix Perspective