Perception · Theory · P3
P3-T3 — Image Coordinates Versus Camera Coordinates
A pixel is not a position. It is a ray, and a position needs one more piece of information: the depth, or a surface the ray must hit.
Going from a point in space to a pixel is projection, and the next question is the reverse: given a pixel, where is the point? The honest answer is “somewhere along a ray”. This lesson defines the three coordinate systems involved (pixels, normalised image coordinates and the camera frame), shows how to turn a pixel into a ray, and then shows the most useful special case in mobile robotics: when the ray meets a flat ground at a known height, the pixel does determine a position, and it can be computed in a few lines.
Learning objectives
After this lesson, you should be able to:
- Convert a pixel to normalised image coordinates and to a ray direction in the camera frame.
- Compute the bearing angles of a pixel and explain why equal pixel steps are not equal angles.
- Back-project a pixel with a known depth, and intersect a ray with a ground plane at a known camera height and pitch.
- Estimate how a one-pixel error changes the ground-plane distance and say where the method becomes unreliable.
The idea: a pixel is a ray
Three coordinate systems appear when you work with a camera:
- Pixel coordinates (u, v): column and row, in pixels, origin at the top left. This is where detections and features live.
- Normalised image coordinates (xn, yn): the position on an imaginary image plane one unit in front of the pinhole, with the origin at the principal point. No pixels, no focal length. Both numbers are the tangent of an angle.
- Camera-frame coordinates (X, Y, Z): metric 3D positions with the origin at the pinhole.
Normalised coordinates are the bridge: xn = X/Z and yn = Y/Z. A pixel fixes only these two ratios, so it fixes the direction of the point from the camera, which is a ray, and leaves the distance along the ray free.
A pixel gives a direction. To get a position add one more constraint: a measured depth, a known size, or a surface that the ray must hit.
The ground plane trick
A wheeled robot drives on a floor, and anything it needs to avoid stands on the floor. If the camera height and pitch are known, every pixel that images the floor corresponds to exactly one floor point, because the ray meets the floor once. That is a depth sensor from a single image, valid as long as the pixel really shows the floor and the floor is flat and level.
The mathematics: pixel, ray, point
Pixel to normalised coordinates and ray
- xn, yn
- normalised image coordinates. For a pixel on the optical axis both are 0. They equal tan of the horizontal and vertical angles from the optical axis.
- r
- a direction (not unit length) from the pinhole towards the scene. The scene point is a multiple of it: (X, Y, Z) = Z · r.
- Z
- the depth along the optical axis, the missing information.
The bearing angles of a pixel are θh = atan(xn) and θv = atan(yn). Note the atan: pixel offsets are proportional to the tangent of the angle, so equal pixel steps are not equal angles. At the border of a 90° field of view, a one-pixel step covers about half the angle that it does at the centre.
Back-projection with a depth
If the depth Z is known (from a depth sensor, Lesson P3-T5):
Ground-plane intersection
Robot frame: x forward, y left, z up. The camera is at height h and pitched down by α (no roll, no yaw offset). The camera axes in the robot frame are: forward (optical axis) (cos α, 0, −sin α), right (0, −1, 0), image-down (−sin α, 0, −cos α). The ray of the pixel in the robot frame is
The camera is at height h, so the ray reaches the floor (z = 0) after a parameter t with h + t Rz = 0, which requires Rz < 0:
The forward distance can be written in terms of the angle below the horizon, the depression angle δ = α + atan(yn):
- α
- the camera pitch below the horizontal.
- δ
- the angle of the ray below the horizontal: pitch plus the pixel’s vertical angle.
- h
- the camera height above the floor, in metres.
- xground, yground
- the floor point in the robot frame, relative to the point on the floor below the camera.
The ray only reaches the floor if δ > 0, i.e. the pixel is below the horizon line. Pixels above the horizon see the sky or distant objects, not the floor, and the formula gives a negative or infinite distance for them.
Sensitivity
Differentiating xground = h/tan δ with respect to δ gives, for small changes,
The error grows with the square of the distance: the floor near the horizon is compressed into a few rows of pixels, so a single pixel row covers many metres.
A worked example: how far is the box?
A robot camera is mounted at h = 1.2 m, pitched down by 10°. It has fx = fy = 600 pixels and principal point (320, 240). A detector reports that the bottom edge of a box, where it touches the floor, is at pixel (u, v) = (420, 400).
- Normalised coordinates: xn = (420 − 320) / 600 = 0.1667, yn = (400 − 240) / 600 = 0.2667.
- Depression angle: δ = 10° + atan(0.2667) = 10° + 14.93° = 24.93°.
- Forward distance: 1.2 / tan(24.93°) = 1.2 / 0.4649 = 2.58 m. (The longer formula gives the same: t = 2.751, x = t (cos α − yn sin α) = 2.58 m.)
- Sideways position: y = −t xn = −2.751 × 0.1667 = −0.46 m, i.e. 0.46 m to the right of the robot’s centreline.
So the box is 2.58 m ahead and 0.46 m to the right.
Sensitivity to one pixel
Now see how much a one-pixel error matters at different rows. Using the same camera:
| Pixel row v | Forward distance | Distance at v + 1 | Change for one pixel |
|---|---|---|---|
| 400 | 2.58 m | 2.57 m | 1.0 cm |
| 300 | 4.27 m | 4.24 m | 2.7 cm |
| 260 | 5.69 m | 5.64 m | 5 cm |
Close to the robot (row 400) one pixel is a centimetre or two; further out (row 260, 5.7 m ahead) one pixel is about 5 cm, and it grows rapidly beyond: the horizon of this camera is at row 134, and at row 140, only 6 rows below it, the floor point is already 128 m away. A detector whose box bottom is uncertain by two or three pixels cannot give a useful distance at long range.
When the assumption fails
The method treats the pixel as a floor point. If the detector’s box bottom is wrong (the top of an object, a shadow, a reflection), or the floor is a ramp, or the camera pitch is off by one degree, the answer is wrong, and it is wrong with confidence. A pitch error of 1° changes δ by 1° everywhere: at δ = 25° that moves the distance from 2.58 m to 2.47 m or 2.70 m, a change of 12 cm or more. Lab P3-L2 showed that a rotation error appears as a constant pixel shift; here it becomes a distance error.
Engineering implications and limitations
State your frame and axes. A pixel-to-ground function has four conventions to fix: the pixel origin, the camera axes, the robot axes and the sign of the pitch. Write them as comments and test with a point you can measure with a tape.
Calibrate height and pitch, not just intrinsics. The ground-plane distance depends directly on the camera height and pitch, which are extrinsics. Measure them after mounting, and recalibrate if the bracket is touched. The pitch can be estimated from the horizon or from a target on the floor.
Choose the right pixel. The ground point is where the object touches the floor: the bottom of the box, the base of a pole, the wheel contact of a car. The centre of a bounding box is not on the floor; use the bottom edge, and check that it is not occluded or cut by the image border.
Gate by distance and by row. Reject or down-weight ground-plane distances beyond the range at which one pixel is more than the accuracy you need, and reject pixels at or above the horizon. Report the uncertainty from the sensitivity formula.
Know the flat-floor assumption. Ramps, kerbs, uneven ground and robot pitch under acceleration violate it. Use IMU pitch to correct the camera pitch each frame, or use depth sensing where the floor is not flat.
Prefer a measured depth when you have one. A depth camera or LiDAR gives distance directly (Module 5 and Lesson P3-T5). The ground-plane trick is cheap and useful as a check on them or when none is available.
Common misconceptions
“A pixel is a position in the world.”
It is a direction. A position needs a depth, or a surface to intersect.
“Pixels are evenly spaced in angle.”
They are evenly spaced on the image plane, so the angle per pixel shrinks towards the edges (it follows 1/(1 + xn²)).
“The distance to a floor point changes linearly with the pixel row.”
The distance is h/tan δ, which changes ever faster as the point approaches the horizon: the last few rows below the horizon cover most of the range.
“Ground-plane distance is as good as a depth sensor.”
It is exact only for a floor point on a flat, level floor with a calibrated camera height and pitch. At range it amplifies each pixel of error into tens of centimetres or metres.
Engineering takeaways
- Pixel → normalised coordinates (u − cx)/fx, (v − cy)/fy → ray (xn, yn, 1); a pixel fixes a direction, not a distance.
- Bearing angles are atan(xn) and atan(yn); equal pixel steps are not equal angles.
- With a depth Z the point is (xn Z, yn Z, Z); with a flat floor, camera height h and pitch α the ground distance is h / tan(α + atan yn).
- The ground-plane distance error from one pixel grows with distance squared: x²e/(h f).
- Fix the conventions, calibrate height and pitch, use the contact point, gate by range, and prefer a measured depth when available.
References and further reading
The worked numbers were computed for this lesson from the formulas shown.
- Hartley, R. and Zisserman, A. (2004). Multiple View Geometry in Computer Vision, 2nd ed. Cambridge University Press: back-projection of points to rays.
- Szeliski, R. (2022). Computer Vision: Algorithms and Applications, 2nd ed. Springer: camera geometry and the use of scene constraints.
- Siegwart, R., Nourbakhsh, I. R. and Scaramuzza, D. (2011). Introduction to Autonomous Mobile Robots, 2nd ed. MIT Press: vision-based obstacle distance from a ground-plane assumption.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A camera with f = 500 pixels and principal point (320, 240) sees a feature at pixel (420, 240). What are xn, the horizontal bearing angle, and what is the offset of the point at depth 5 m?
Explanation
xn = (420 − 320)/500 = 0.2. The bearing is atan(0.2) = 11.3°. At Z = 5 m the lateral offset is xn Z = 1.0 m to the right of the optical axis.
Question 2
A level camera (no pitch) is mounted 1.0 m above the floor. A floor point appears 100 pixels below the principal point and fy = 500. How far ahead is the point?
Explanation
yn = 100/500 = 0.2 and the depression angle is atan(0.2) = 11.3°. Distance = h/tan δ = 1.0 / 0.2 = 5.0 m. (With no pitch the formula reduces to h/yn.)
Question 3
Why can a robot trust the ground-plane distance to a box 1.5 m away more than to one 15 m away, even if the detector is equally precise?
Explanation
The pixel error sensitivity grows as the square of the distance: one pixel changes the distance by x²e/(h f). At 1.5 m that is a few millimetres to a centimetre or two; at 15 m it is one hundred times larger, several metres for the same pixel error. The horizon compresses far ground into few rows.
What’s next
Next: why one image cannot give depth, how size, motion and context constrain it, and how much those cues are worth.
Related content
Nothing below is required to finish this lesson.
- BeforeP3-T2: Intrinsic and Extrinsic Calibration
Distinguish intrinsic and extrinsic parameters and describe how they are estimated.
- LabP3-L1: Project 3D Points into an Image
Implement pinhole projection and use it to place known 3D objects in an image.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.