Skip to the lesson
FixTheRobot Explore Robotics / Perception / P3 Geometry and Camera Perception / P3-T3

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.

  • Lesson 3 of 6
  • Module 3: Geometry and Camera Perception
  • Theory
  • About 11 minutes to read

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 camera on a robot looking at the groundA side view. A camera at height h above a flat floor, pitched down by alpha. The optical axis points forward and down. A ray for a pixel below the image centre is steeper and meets the ground at a distance d ahead of the robot. The depression angle of the ray is alpha plus the arctangent of y_n.floor robot camera h optical axis (pitched down by α) ray for a pixel below the centre floor point d Each pixel is a ray. The floor turns a ray into a point.
The camera at height h, pitched down by α. A pixel below the image centre gives a ray that is steeper than the optical axis. The floor is the surface that ends the ray and turns it into a point.

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

pixel to ray
xn=u−cxfxx_{n}=\frac{u-c_{x}}{f_{x}}
yn=v−cyfyy_{n}=\frac{v-c_{y}}{f_{y}}
ray direction in the camera frame: r=(xn, yn, 1)\text{ray direction in the camera frame}:\,r=(x_{n},\,y_{n},\,1)
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):

back-projection
X=xn Z=(u−cx) ZfxX=x_{n}\,Z=\frac{(u-c_{x})\,Z}{f_{x}}
Y=yn Z=(v−cy) ZfyY=y_{n}\,Z=\frac{(v-c_{y})\,Z}{f_{y}}

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

ray in the robot frame
R=xn⋅right+yn⋅down+forward=(cos⁡ α−yn sin⁡ α, −xn, −sin⁡ α−yn cos⁡ α)R=x_{n}\cdot \text{right}+y_{n}\cdot \text{down}+\text{forward}=(\cos \,\alpha -y_{n}\,\sin \,\alpha ,\,-x_{n},\,-\sin \,\alpha -y_{n}\,\cos \,\alpha )

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:

floor point
t=hsin⁡ α+yn cos⁡ αt=\frac{h}{\sin \,\alpha +y_{n}\,\cos \,\alpha }
xground=t(cos⁡ α−yn sin⁡ α)x_{\text{ground}}=t(\cos \,\alpha -y_{n}\,\sin \,\alpha )
yground=−t xny_{\text{ground}}=-t\,x_{n}

The forward distance can be written in terms of the angle below the horizon, the depression angle δ = α + atan(yn):

forward distance from the depression angle
xground=htan⁡ δx_{\text{ground}}=\frac{h}{\tan \,\delta }
α
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,

distance error from a one-pixel error
d xgroundd v≈xground2h fy\frac{d\,x_{\text{ground}}}{d\,v}\approx \frac{x_{\text{ground}}^{2}}{h\,f_{y}}
so a pixel error e changes the distance by about xground2 eh fy\frac{\text{so}\,a\,\text{pixel error}\,e\,\text{changes the distance by about}\,x_{\text{ground}}^{2}\,e}{h\,f_{y}}

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).

  1. Normalised coordinates: xn = (420 − 320) / 600 = 0.1667, yn = (400 − 240) / 600 = 0.2667.
  2. Depression angle: δ = 10° + atan(0.2667) = 10° + 14.93° = 24.93°.
  3. 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.)
  4. 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:

Effect of a one-pixel row error on the ground-plane distance
Pixel row vForward distanceDistance at v + 1Change for one pixel
4002.58 m2.57 m1.0 cm
3004.27 m4.24 m2.7 cm
2605.69 m5.64 m5 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

  1. Pixel → normalised coordinates (u − cx)/fx, (v − cy)/fy → ray (xn, yn, 1); a pixel fixes a direction, not a distance.
  2. Bearing angles are atan(xn) and atan(yn); equal pixel steps are not equal angles.
  3. 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).
  4. The ground-plane distance error from one pixel grows with distance squared: x²e/(h f).
  5. 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.

Practice this lesson

Project 3D Points into an Image

Implement pinhole projection and use it to place known 3D objects in an image.

Next lesson

P3-T4 — Perspective and Depth Ambiguity

Explain why one image cannot give depth and how scale, size and motion relate.

Nothing below is required to finish this lesson.