# Scaling axes to reflect perspective plane of an image.

Suppose I have an image which contains a road in it, and I want to be able to pinpoint the locations of cars on that road using pre-calibrated distances. How to do that using formulas that map pixel coordinates to the calibrated distances?

A method I have thought of to do this is described as follows. Suppose I have the following image:

What I do is calibrate the y-axis with real distances, those that are straight away from the camera. However, as can be seen in the above image, the y-axis will become a non-linear one. Then, I find a relationship that maps the y-coordinate of the pixels in the image to the real distances. Perhaps, plotting a graph of pixel y-coordinate against calibrated distance will allow me to find this relationship.

Anytime I have to find the y-coordinate of the real location of a car, I just get it from the derived relationship by inputting the y-coordinate of the pixel location of the car.

Now, the location of a car also consists of an x-coordinate. To get this, what I do is first calibrate the x-axis of the image with real distances. The x-axis will be a linear one, however, the scale obtained from the calibration will be valid for points only at the x-axis. As we move up the image, the scale becomes invalid because as I understand, the step of the x-axis should decrease as we move up the image as shown below:

What I can do is find a relationship that maps the x-coordinate of a pixel to the real distances along the x-axis. However, the real distances along the x-axis depend on the step of the x-axis and the step of the axis depends on the real y-coordinate of that pixel. So, what I need in fact is a relationship that covers all these parameters.

If the described method above is correct, then what I need to know is the following:

• How to find a relationship that maps the pixel y-coordinate of a location in the image to the real/calibrated y-coordinate, given that I have already calibrated the real distances on the y-axis using measured values.
• How to find a relationship that maps the step of the x-axis to the real/calibrated distances on the y-axis.
• How to find a relationship that maps the pixel x-coordinate of a location in the image to the real/calibrated x-coordinate, given that the step of the x-axis has already changed accordingly.

If the described method isn't correct, then please suggest another one, preferably an easier one.

Thank you.

• If you know the road-plane coordinates of four points in general position (no three colinear) in the image, you can compute a homography that maps between the image and road planes. See math.stackexchange.com/a/339033/265466. – amd Oct 27 '18 at 7:54