# A formula for Perspective measurement

If I have a photograph of a rectangular object whose image recedes with perspective, is it possible to work out the scale of measurements along that object?

For example: I have a photograph of a (metric) ruler.

The ruler is graduated in centimetres as shown, 30 cms.

Is it possible to work out the distance between each centimetre?

The screenshot shows the photograph.

The representation on the Picture Plane shows the nearest edge of the ruler to be 50mm and the farthest edge to be 15mm. By measuring the photo, I see that the distance between 0 and 1 is 7.5mm and the distance between 27 and 28 is 0.9mm.

Is there a way to get these results from a formula?

It doesn't need to be 100% accurate: it's for photometric software I'm writing, so it's only going to be used as a rough guide.

There are many ways to interpret your question, and even if you only need one, others might be interested in other, so I'll write about a few of them.

# Projective transformation of the plane

You ask whether the same results you obtained by measuring the photo could also be obtained from a formula. The answer is yes, if you know the transformation. The class of transformations which describes a perspective deformation of a planar figure is the class of plane projective transformations, which can be represented as $3\times 3$ matrices. That matrix can be computed from the images of four points. So if you know the corners of the ruler in your photo, then you can compute all the rest.

# 3D computation

If you don't know the corners, but do know where your camera is in relation to the ruler, then you could express all of this as a sequence of 3d transformations and a final projection, resulting in a similar $3\times 3$ matrix in the end.

# Scale along a line

A projective scale is uniquely defined by three points, which I'll call $P_0$, $P_1$ and $P_\infty$. You can interpret the first as origin, the second as unit step, and the third as the point at infinity. That last one you can obtain in your photo by intersecting the images of the parallel edges of the ruler. The point where these intersect is the image of infinity. The other two would likely be 0 cm and 1 cm, or perhaps beginning and end of the ruler. If you have these three fixed, then you can use them to measure distacnes using the cross ratio:

$$\operatorname{CR}(P_\infty,P_0;P_1,P_\lambda)=\lambda$$

So given three points defining the scale, you can compute the original (non-perspective) position using the above formula. And conversely, given the original position, you can find the corresponding point in the photograph.

# Constructing a projective scale

Points at integral positions along a perspectively deformed scale can also be constructed geometrically. Here is an interactive illustration of that construction. The site is in German (so far), so here is an explanation:

$0$, $1$ and $\infty$ fix your scale. Draw two arbitrary lines through $\infty$. Choose an arbitrary point on the lower line (drawn in white) and connect it to $0$ and $1$. You obtain two points on the upper line (drawn in black). Then start by the maximal point you have so far, i.e. $1$, connect to the right black point, intersect with the lower line, connect to the left black point, intersect with the line of the scale, and you obtain $2$. The steps to go from $i$ to $i+1$ are the same for all $i\in\mathbb N$.

• Thanks for responding. I've managed to work out how to do it. It really was a matter of setting out the question which then made it clearer to me. What I did was this: ![Fig 1][1] I drew the rectangle ABCD in perspective using the measurements given above. I then drew E-F which is 7.5mm from A-B which represents the graduation at 1cm. I could have chosen any distance but have decided to use the value from the photograph. I then drew a line from B through the mid point of E-F. ![Fig2][2] [1]: i.stack.imgur.com/RCVCg.png [2]: i.stack.imgur.com/KHgDh.png – Dave Coventry Dec 20 '13 at 11:29
• ...continued:I extended this line to intersect the line A-D. I then drew the line G-H. ![Fig3][3] I repeated this until I had all the divisions marking the graduation of the ruler. Happiness! ![Fig4][4] [3]: i.stack.imgur.com/bKERG.png [4]: i.stack.imgur.com/kFvOB.png – Dave Coventry Dec 20 '13 at 11:31
• @DaveCoventry: Keep in mind that midpoints are not a projective invariant: there are perspectives which will map the midpoint to something other than the midpoint. In your photo it only works because all your graduation lines are still parallel in the image. If that will always be the case, you are fine, otherwise you should rather use this scale construction from my last paragraph. – MvG Dec 20 '13 at 11:34
• Is there a proper name for your "Scale along a line" formula? I don't understand how it works and want to look it up. – skibulk Apr 19 '16 at 20:09
• @skibulk: Using three points to define a projective scale is also called a (one-dimensional) projective basis. It works by observing that for homogeneous coordinates $P_0=(0,1)$, $P_1=(1,1)$, $P_\infty=(1,0)$, $P_\lambda=(\lambda,1)$ the equation holds, so it is true in the non-deformed setup. On the other hand, the cross ratio remains invariant under projective transformations, so this way of measuring distances must remain valid for projectively deformed setups as well. Perhaps this post of mine can be of use to you, too. – MvG Apr 19 '16 at 21:12

These two vector equations can define any points in perspective by inputting x,y,z coordinates of points for the object and outputting X,Y coordinates in perspective. Keep in mind that perspective projections can look different when the camera is tilted for bird's eye views. Thus, a tilt angle of the camera can be incorporated into the equations. Anyway, try to test them, then I can give you more details about their application. These are Murran's perspective equations.