<p>An affine transformation doesn't have enough freedom to do what you want. Affine transforms can be constructed to map any triangle to any other triangle, but they can't map any quadrilateral to any other quadrilateral.</p>

<p>One way to see this is that the matrix for a 2D affine transform has only 6 free coefficients. That's enough to specify what it does to 3 points, but not 4.</p>

<p>For this task you likely want a projective transformation. A 2D projective transformation has enough freedom to <a href="http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/" rel="noreferrer">map any convex quadrilateral to any other</a>.</p>

CC BY-SA 3.0
2017-11-07T20:54:25.020Z
2017-11-07T20:54:25.020Z
Nathan Reed
<p>I am trying to use a linear transformation to straighten out the camera angle on this image:</p>

<p><a href="https://i.sstatic.net/03ys6.jpg" rel="noreferrer"><img src="https://i.sstatic.net/03ys6.jpg" alt="enter image description here"></a></p>

<p>In other words, I want to transform the image into a head-on view of the whiteboard.</p>

<p>I applied an affine transformation to that image, identifying the top left, top right, and bottom left corners, thinking that it would turn the image into a 1080x720 rectangle. However, here's what I ended up with:</p>

<p><a href="https://i.sstatic.net/k5UFZ.png" rel="noreferrer"><img src="https://i.sstatic.net/k5UFZ.png" alt="enter image description here"></a></p>

<p>As you can see, it is NOT a rectangle, but some sort of misshapen quadrilateral. It's close, but not exactly a head-on view of the whiteboard!</p>

<p>What exactly happened here? I really thought an affine transformation would work.</p>

<image-processing><affine-transformations><linear-algebra>
Why does an affine transform work only on three of the corners?
Lincoln Bergeson
# Why does an affine transform work only on three of the corners?

(Asked by: username_0 on 2017-11-07)

I am trying to use a linear transformation to straighten out the camera angle on this image:

[![enter image description here](https://i.sstatic.net/03ys6.jpg)](https://i.sstatic.net/03ys6.jpg)

In other words, I want to transform the image into a head-on view of the whiteboard.

I applied an affine transformation to that image, identifying the top left, top right, and bottom left corners, thinking that it would turn the image into a 1080x720 rectangle. However, here's what I ended up with:

[![enter image description here](https://i.sstatic.net/k5UFZ.png)](https://i.sstatic.net/k5UFZ.png)

As you can see, it is NOT a rectangle, but some sort of misshapen quadrilateral. It's close, but not exactly a head-on view of the whiteboard!

What exactly happened here? I really thought an affine transformation would work.

**Tags:** image-processing, affine-transformations, linear-algebra


---

## 1 answers

### Answer by username_1 on 2017-11-07. Score: 6 | Accepted answer

An affine transformation doesn't have enough freedom to do what you want. Affine transforms can be constructed to map any triangle to any other triangle, but they can't map any quadrilateral to any other quadrilateral.

One way to see this is that the matrix for a 2D affine transform has only 6 free coefficients. That's enough to specify what it does to 3 points, but not 4.

For this task you likely want a projective transformation. A 2D projective transformation has enough freedom to [map any convex quadrilateral to any other](http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/).


---

