3D visionExplainer

Why focal length in pixels: the mm times pixels unit mystery

Calibration reports fx in pixels because s is pixel density, px/mm, not a pixel count: mm × px/mm = px. Unit algebra, worked example, sanity checks.

LumaSpec Vision9 min read Share on LinkedIn

On this page 9 sections
  1. 01The answer: s is a density, not a count
  2. 02Why the camera matrix speaks pixels
  3. 03Worked example: 90 mm field of view at 200 mm
  4. 04The reverse: reading fx as a lens in millimetres
  5. 05What moves fx, and by how much
  6. 06Checks before you trust an fx
  7. 07When the pixel answer misleads you
  8. 08Choosing the hardware that carries it
  9. 09Questions

Calibration software hands you a camera matrix with fx = 2,319 px and calls it a focal length. The formula behind it reads f = F × s, states that F is in millimetres and s is in pixels, and then claims f is in pixels. Multiply millimetres by pixels and you should get millimetre-pixels, so something in that sentence is shorthand. It is. The s is not a count of pixels; it is a density, pixels per millimetre of sensor, and the millimetres cancel. This explainer is for engineers wiring camera calibration into a vision system who hit that unit wall. You will see the algebra, convert a real lens from millimetres to matrix pixels and back, and run the checks that catch a wrong fx before it corrupts a 3D measurement.

The answer: s is a density, not a count

The contradiction disappears once s carries its full unit. In f = F × s, F is the lens focal length in millimetres and s is the sensor's pixel density along one axis: how many pixel columns fit into one millimetre of sensor. Documentation tables shorten "pixels per unit length" to "pixels", and that abbreviation is where the confusion starts.

s = 1 / pixel pitch (pixels per mm) fx = F × s

Run the units through the product: mm × (px/mm) = px. The millimetres cancel and pixels survive. Take a sensor with 5 µm pixels: s = 1 / 0.005 mm = 200 px/mm, so a 16 mm lens gives fx = 16 × 200 = 3,200 px. The lens did not change; you switched the ruler from millimetres to sensor pixels. Documentation lists sx and sy separately because the two sensor axes are measured separately, and on a square-pixel sensor they are equal.

Why the camera matrix speaks pixels

Pixels are the only language the projection equations use. A pinhole camera images a point at depth Z onto the sensor at u = f × X / Z, with u in millimetres. Your software indexes that position in pixels, so it multiplies by the density: u_px = (s × f) × X / Z. The product s × f is the only thing that survives into the matrix, written fx, because f in millimetres never appears on its own again.

The principal point cx, cy is stored in pixels for the same reason: it gets added to pixel coordinates. Every entry of the intrinsic matrix carries pixel units so it can multiply and add against pixel coordinates. fx is simply f expressed with the pixel as the unit of length. The Wikipedia camera resectioning page writes the same relation as fx = f · mx with mx = 1 / dx, where dx is the pixel size — one density in different letters.

Worked example: 90 mm field of view at 200 mm

Pick the sensor first, because it owns the conversion. A common 2/3" industrial sensor runs 2,448 pixels across at a 3.45 µm pitch, which is 2,448 × 0.00345 mm = 8.45 mm of active width. Its density is s = 1,000 / 3.45 = 289.9 px/mm. That single number converts every lens you will ever mount in front of this sensor.

The part measures 90 mm across and the station allows about 200 mm of working distance. Magnification: m = 8.45 / 90 = 0.0939. Focal length: f = WD × m / (1 + m) = 200 × 0.0939 / 1.0939 = 17.2 mm. Stock C-mount glass steps in roughly 6, 8, 12, 16, 25 and 35 mm, so the choice is a 16 mm lens — the millimetre-side decision, worked through in how to choose a machine vision lens focal length.

How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.

The 16 mm lens reaches the full 90 mm field of view at WD = 16 × 1.0939 / 0.0939 = 186 mm. Left at 200 mm it sees 8.45 / (16 / 184) = 97 mm, a little margin at no cost. Now the conversion this article exists for: fx = 16 mm × 289.9 px/mm = 4,638 px.

Cross-check against the image width: 4,638 / 2,448 = 1.89, and f / active width = 16 / 8.45 = 1.89. The same ratio from two directions, so the arithmetic holds. Object-side sampling follows from the magnification: 3.45 µm / 0.0939 = 36.7 µm per pixel, and 2,448 × 0.0367 mm = 89.8 mm — the designed field of view. The object-space number is its own subject: calculate object space pixel size from magnification works it in depth.

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

The reverse: reading fx as a lens in millimetres

A calibration report gives fx; the lens on the camera is what you want. Multiply by the pitch, which is dividing by the density: f = fx × pixel pitch. The same 2/3" camera reporting fx = 1,739 px is carrying f = 1,739 × 0.00345 mm = 6.0 mm, a 6 mm lens. A result of 6.4 mm on a lens marked 6 mm is focus breathing plus fit noise; a result far from any stock focal length means the pitch you assumed is wrong. Unit discipline pays on the output side too: marker pose units: tvec comes out in the unit of the marker length covers the translation vector, and camera calibration for length measurement from image markers carries pixels back to millimetres on the object.

What moves fx, and by how much

Baseline: the 2/3" sensor above with an 8 mm lens, fx = 2,319 px.

Change fx becomes Arithmetic
Sensor with 2.4 µm pixels, same 8 mm lens 3,333 px 8 × (1,000 / 2.4) = 8 × 416.7
2×2 binning on this camera 1,160 px pitch doubles to 6.9 µm
1.4× zoom on a varifocal 3,247 px 2,319 × 1.4; f becomes 11.2 mm
Half-resolution images downstream 1,160 px every intrinsic scales with the image

Two rows land on the same value by different routes, and both are real: binning builds bigger pixels, resampling just relabels them. 4x4 binning vs 2x2: sensor readout decides your frame rate covers the readout consequences of that choice.

Checks before you trust an fx

Run these five checks on any calibration output before it enters production:

  1. fx and fy agree within 0.5 % on a square-pixel sensor. A gap approaching 1 % with a clean fit means the pipeline stretches the image somewhere.
  2. fx / image width equals f / active width. Here 4,638 / 2,448 = 1.89 matches 16 / 8.45 = 1.89; a mismatch points at the assumed pitch.
  3. cx and cy sit within about 5 % of the image width from the centre. A corner value means the target set was lopsided.
  4. RMS reprojection error lands between 0.1 and 0.5 px. Above that, add target angles and distances before blaming the units.
  5. The angle closes the loop: 2 × atan(2,448 / (2 × 4,638)) = 29.6°, the horizontal field of view of a 16 mm lens over 8.45 mm. Calculate camera angle of view from calibration turns fx into degrees.

When the pixel answer misleads you

  • Resized or cropped streams. fx belongs to the resolution it was calibrated at. Halve the image and fx, fy, cx, cy all halve; crop instead and fx, fy stand while cx, cy shift by the crop offset.
  • "Pixel size" in a datasheet. Use the pixel pitch, the centre-to-centre spacing, not the photosensitive area of one pixel.
  • Non-square pixels or anamorphic glass. fx ≠ fy is then physically correct, not noise.
  • Zoom and autofocus. Every focus change is a small focal change; calibrate a camera with autofocus: lock the focus first is the procedure.
  • Depth and fisheye cameras. A single pinhole fx does not describe an equidistant lens; depth camera pixel pitch: get it without a datasheet handles the sensors where the pitch itself is the unknown.

Choosing the hardware that carries it

The lens decision happens in millimetres; calibration rewrites it in pixels. Filter machine vision lenses by focal length and mount, or let the lens finder narrow the list. The 35 mm LS-FFL-0679 is a 6 MP C-mount option in that range.

Machine vision lenses35 mm, 2/3", 6 MP, C-mount machine vision lens (LS-FFL-0679)LS-FFL-0679
Type
Machine vision fixed
Sensor format
2/3"
Mount
C-mount
Resolution
6-10 MP
$219.00View partBuild a system with it

On the camera side, any C-mount area scan camera takes the pair; the sensor's pitch is the one number this conversion needs, and it comes from the sensor data sheet.

Area scan camerasHikrobot MV-CT0MG0060/R/NN/NN 6 MP Area Scan Camera, 3rd Gen., GigE, Mono, BASEMV-CT0MG0060/R/NN/NN
Sensor format
1/1.8"
Lens mount
C-mount
Interface
GigE
Resolution
6-10 MP
$909.00View partBuild a system with it

Start with the lens focal length calculator for the millimetre side, then configure the station end to end. If a sensor's pitch is not stated anywhere you can find, the contact page reaches an applications engineer who can pin it down.

Questions

How do I convert focal length in pixels back to millimetres?

Multiply fx by the pixel pitch in millimetres. A report showing fx = 1,504 px on a sensor with 5.32 µm pixels means f = 1,504 × 0.00532 mm = 8.0 mm, so the camera carries an 8 mm lens. Watch the units you carry: a pitch in micrometres gives micrometres out, so divide by 1,000 for millimetres.

Why are my fx and fy slightly different?

On a square-pixel sensor they should match. Differences under about 0.5 % are estimation noise from a limited target set; add images at more angles and distances and they converge. A persistent gap near 1 % or more points to non-square pixels, an anisotropic stretch in the pipeline, or a poor fit. Check the reprojection error before trusting either value.

Does binning or a smaller ROI change the focal length in pixels?

Binning does; a crop does not. 2×2 binning merges four sensor pixels into one output pixel, so the effective pitch doubles from 3.45 µm to 6.9 µm and fx halves from 2,319 px to 1,160 px. Cropping keeps the pitch, so fx and fy stand unchanged, but cx and cy shift by the crop offset.

Can I compare fx between two cameras?

Only if the pixel pitch is identical. fx = f × pixels per millimetre, so smaller pixels inflate fx without changing the optics: a 12 mm lens reads 3,479 px on a 3.45 µm sensor and 5,000 px on a 2.4 µm one. Compare angles instead. 2 × atan(image width / (2 × fx)) is the horizontal field of view, and that number travels between cameras.

What if the calibration ran on resized images?

Scale every intrinsic by the resize factor before use. Calibrate at full resolution, then feed half-size frames to your code, and fx, fy, cx and cy all halve: 2,319 px becomes 1,160 px. Get this wrong and every projection is off by the same factor, so a 3D point lands tens of pixels from where your code expects it.