System designExplainer

Undistorted image and the pinhole camera model: when x = fX/Z holds

When an undistorted image obeys the pinhole camera model, what x = fX/Z really means, the principal-point offset, and a worked projection example.

LumaSpec Vision10 min read Share on LinkedIn

On this page 9 sections
  1. 01The short answer: yes, with two conditions
  2. 02What each term of the equation is
  3. 03What the remap changes and what it leaves alone
  4. 04Worked example: 20 mm feature at 400 mm with a 16 mm lens
  5. 05Scaling, binning and cropping
  6. 06When the pinhole model stops being true
  7. 07When you can skip the remap
  8. 08Checks before you trust the numbers
  9. 09Questions

You calibrated the camera, remapped the distortion out of the frames, and now you want to measure parts with the simple projection equation x = fX/Z. The answer here is written for single-camera metrology after an OpenCV-style calibration: when the undistorted image behaves as a pinhole camera, which camera matrix to use on it afterwards, and where every term of the equation lives. A worked projection at 400 mm gives the scale, field of view and sensitivity numbers, and the closing sections name the cases — fisheye, telecentric, through-glass — where the equation must not be used at all.

The short answer: yes, with two conditions

Once a calibrated remap has removed the radial and tangential distortion, the undistorted image is consistent with the pinhole camera model, and projection is:

x = fx · X / Z + cx y = fy · Y / Z + cy

The equation you started from, x = fX/Z, is this same relation in centered, normalized coordinates. It is true only when x is measured from the principal point (cx, cy) rather than the image corner, and when (X, Y, Z) are coordinates in the camera frame: Z along the optical axis, X to the right, Y down, origin at the projection center. Get either wrong and every coordinate silently shifts by tens of pixels.

The second condition is the lens. A rectilinear lens, remapped with its own distortion coefficients, lands exactly on the pinhole model. A fisheye lens and an object-side telecentric lens never do, whatever you remove from their images.

Note also what the remap does not do: the default behavior of the OpenCV undistortion functions leaves the principal point alone, so the matrix you calibrated is still the matrix of the undistorted image. Keep fx, fy, cx and cy, add the offsets, divide by Z. Only if you ask the undistortion for a changed output matrix — rescaled or cropped — do you carry new values forward, and how the principal point moves after undistortion shows which.

What each term of the equation is

fx and fy are focal lengths in pixels, not millimeters. The conversion is the pixel pitch:

fx = f / p

with f the focal length in mm and p the pixel pitch in mm. A 16 mm lens on a 2.0 µm pitch gives fx = 16 / 0.002 = 8000 px. The pitch comes from the sensor data, not from the pixel count alone — a camera such as the LS-CMR-0166, a 12 MP USB3 camera with a 4000 × 3000 grid, is the known pixel geometry these equations want.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

cx and cy locate where the optical axis meets the sensor: near the image center, not on it. Calibration measures them; assuming the exact center costs accuracy, and principal point uncertainty and when to distrust your calibration says how far is too far. For the full forward and inverse routines, projecting a 3D point to pixel coordinates with a calibrated camera walks through the code.

What the remap changes and what it leaves alone

Calibration returns two things: the intrinsic matrix (fx, fy, cx, cy) and the distortion coefficients — radial and tangential, the Brown-Conrady family. initUndistortRectifyMap() plus remap() resamples the frame so straight lines in the world are straight in the image; undistort() does the same in one call, and undistortPoints() maps individual coordinates back to rays. The default of these functions keeps cx and cy where they were, which is why the old matrix stays valid for the new image.

If your calibration call fixed the aspect ratio, assumed zero tangential distortion or pinned the principal point, those assumptions are folded into the matrix you now hold. For measurement work, leave them free unless the fit refuses to converge.

Two practical notes. Remapping resamples, so measure edges on the undistorted frame, never on the raw one. And the remap leaves black borders where it had to invent pixels; when you crop them away, subtract the crop offset from cx and cy — black borders after undistortion covers where to cut. When the coefficients themselves are in doubt, Brown-Conrady distortion fitting from point pairs alone refits them without a checkerboard, and recalibrating lens distortion coefficients lists the triggers.

Worked example: 20 mm feature at 400 mm with a 16 mm lens

Example inputs: a 4000 × 3000 sensor with a 2.0 µm pixel pitch, a 16 mm lens, a part at Z = 400 mm, and a calibration that returned cx = 2000 px and cy = 1500 px. Values this close to the center are typical; yours come from your own calibration file.

  • Sensor size: 4000 × 0.0020 mm = 8.0 mm wide, 3000 × 0.0020 mm = 6.0 mm high.
  • fx = fy = 16 mm / 0.0020 mm = 8000 px.
  • Scale at the part: fx / Z = 8000 / 400 = 20 px per mm, so 1 px of image is 0.05 mm of object.
  • Field of view: 400 mm × 8.0 mm / 16 mm = 200 mm wide and 150 mm high. Cross-check: 4000 px ÷ 20 px/mm = 200 mm.
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.

Projecting a corner at (X, Y, Z) = (15, 10, 400) mm:

x = 8000 × 15 / 400 + 2000 = 2300 px y = 8000 × 10 / 400 + 1500 = 1700 px

Measuring instead of projecting: two edges land at 2200 px and 2600 px, so the feature is (2600 − 2200) / 20 = 20.0 mm wide. Depth from known size inverts the equation: a 25 mm gauge spanning 520 px sits at Z = fx × W / w = 8000 × 25 / 520 ≈ 385 mm — 15 mm nearer than the nominal 400 mm.

Sensitivity decides the method. Each pixel of edge noise moves that depth estimate by fx × W / w² = 200,000 / 270,400 ≈ 0.74 mm, so a two-edge measurement wanders by about 1.5 mm. Working distance cuts the other way: 1 mm of Z error at 400 mm is a 0.25% scale error, 0.05 mm on a 20 mm feature.

The decision: use the single camera for planar X-Y measurement, where 1 px is 0.05 mm, and do not use size-based depth when you need better than about 1 mm — add a second view or a distance sensor instead. The lens focal length calculator sizes the field of view before you commit to the working distance.

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

Scaling, binning and cropping

When an image is scaled by a factor, fx, fy, cx and cy scale by that same factor and the distortion coefficients stay unchanged. That one rule covers the common re-uses of a calibration: 2×2 binning halves the four intrinsic values, and a crop by (x0, y0) subtracts x0 from cx and y0 from cy while the focal lengths stay put. Neither forces a recalibration. Physical change does — refocusing moves the effective focal length, and a different lens or working-distance regime needs its own fit.

When the pinhole model stops being true

Fisheye and very wide lenses map angle, not tangent. The Brown-Conrady family fitted to a fisheye leaves large residuals, and forcing a pinhole remap stretches the corners badly. Use the fisheye distortion model and project with the matrix it returns; matching the fisheye distortion model shows what breaks when the two get mixed.

Object-side telecentric lenses image X at constant magnification: x = m · X + cx, with no division by Z. That is precisely why metrology uses them — size does not drift with standoff inside the depth of field. A fixed-magnification lens such as the LS-TCL-0574, a 0.4x design with a 227 mm working distance, works this way; keep the pinhole equation away from its images.

Machine vision lensesFixed-magnification lens, 0.4x, 227 mm WD, 1.2" (LS-TCL-0574)LS-TCL-0574
Sensor format
1.2"
Mount
C-mount
Image circle
16-22 mm
$2,269.00View partBuild a system with it

A refractive interface — a glass window or a water layer — bends the ray, and no lens distortion coefficient absorbs that. Underwater stereo calibration against the pinhole model quantifies the drift a port introduces; the same physics applies to an inspection window on a washdown cell.

Residual calibration error: the remap is only as good as its coefficients. Hold reprojection error at or below a few tenths of a pixel. At this example's 0.05 mm per pixel, 0.3 px of residual is about 0.015 mm of geometry — an order of magnitude below the 1 px of edge noise you already accept.

Motion during exposure: a rolling-shutter camera reads the part row by row, so a moving part is photographed at slightly different instants top and bottom. The projection equation is untouched, but the (X, Y, Z) it refers to is no longer one moment. Freeze the part with a strobe or use a global-shutter camera.

When you can skip the remap

If the distortion you would remove is smaller than your tolerance, the remap is optional, and you save a resampling step. The LS-FFL-0567 is a 16 mm C-mount lens for 1.1" sensors, rated at 20 MP with distortion below 0.3%.

Machine vision lenses16 mm, 1.1", 20 MP, C-mount machine vision lens, F2.8-22, <0.3% distortion (LS-FFL-0567)LS-FFL-0567
Type
Machine vision fixed
Sensor format
1.1"
Mount
C-mount
Resolution
16-25 MP
$679.00View partBuild a system with it

At the worked example's 200 mm field, 0.3% of the 100 mm half-field is about 0.3 mm of corner displacement, falling to zero at the center. Inside a ±0.5 mm tolerance you can measure on the raw frame; at ±0.05 mm, calibrate and remap. The machine vision lenses category and the lens finder list distortion class alongside focal length, so you can filter for lenses that keep you on the right side of that line.

Checks before you trust the numbers

Run these once, before the first production measurement:

  • Reprojection error of the calibration at or below a few tenths of a pixel, taken at the focus and working distance you will use.
  • A known gauge re-measured: place a 25 mm artifact, read Z = fx × W / w, and compare with a tape or laser measure — the worked example's 385 mm against 400 mm shows what a 15 mm miss looks like.
  • cx and cy read from the calibration file, never assumed to be the image center; a principal point fitted far outside the frame is itself a red flag — principal point outside the image says when the calibration is still usable.
  • One source of truth: the same matrix that built the remap is the one you project with.
  • The part stationary during exposure, or the exposure short enough that it is.
  • Nothing refractive between lens and part.

When all six close, x = fx · X / Z + cx is trustworthy down to your edge noise. To size the camera and lens for a target field of view first, start at the lens step of the configurator, browse area scan cameras by resolution and mount, or read the wider systems topic. For a specific measurement cell, the contact page reaches our applications team.

Questions

After the remap, which camera matrix do I use for the projection?

The one your calibration returned, unchanged. The default OpenCV undistortion does not move the principal point, so the fx, fy, cx and cy you calibrated are exactly the matrix of the undistorted image. Only if you told the undistortion to write a different output matrix — to rescale or crop the result — do you project with that output instead.

Can I write x = fX/Z without cx if I center my coordinates first?

Yes. Subtract cx and cy from your pixel coordinates and the equation reduces to x_c = fx·X/Z and y_c = fy·Y/Z, the normalized pinhole form. That is all the bare formula ever meant: camera-frame coordinates and a pixel origin at the principal point. In corner-origin pixel coordinates, the + cx and + cy terms are mandatory.

Does 2x2 binning force a recalibration?

No. Scaling an image by a factor scales fx, fy, cx and cy by that same factor and leaves the distortion coefficients unchanged, so binning by two just halves the four intrinsic values. Recalibrate when something physical changes — a refocus, a different lens, a new working-distance regime — or when the check on a known gauge stops closing.

Does the pinhole equation hold through an inspection window or under water?

No. A flat port or water layer refracts the ray, so a single straight line from point to pixel no longer describes the geometry, and no lens distortion coefficient absorbs the effect. Keep the port out of the optical path, or model the refraction explicitly as a ray-traced system the way underwater stereo calibration does.

How accurate is depth from object size with one camera?

Treat it as a millimeter-class estimate. In the worked example (fx = 8000 px, a 25 mm gauge spanning 520 px), one pixel of edge noise moves the depth by fx·W/w², about 0.74 mm, so a two-edge measurement wanders by roughly 1.5 mm. Planar X and Y at the same geometry cost 0.05 mm per pixel — twenty times better.