Skip to content

How a Lens Forms an Image: Focal Length, Field of View, Aperture and Depth of Field

A calibration describes a lens with a handful of numbers: a focal length in pixels, a principal point and some distortion terms. Those numbers come from physics. This page covers the physics a practitioner needs to read a lens datasheet, predict what a camera will see, and understand what a calibration is actually measuring.

Every example on this page uses the same illustrative camera, so the numbers can be followed from section to section:

  • a sensor of 1280 × 800 pixels with a pixel pitch of 3.0 µm (micrometres);
  • a lens with a focal length of 2.0 mm and an f-number of 2.0.

The camera calibration guide explains what intrinsics and extrinsics are and how they are estimated. This page explains where they come from.

A pinhole camera is a dark box with a tiny hole. Each point in the scene sends one thin bundle of light through the hole, and it lands on one spot on the back wall. That is the model every calibration starts from: all rays pass through a single point, the centre of projection, and the image is the scene projected through that point.

A real pinhole has two problems. A small hole lets in very little light. A very small hole also blurs the image by diffraction. A lens solves both: it collects light over a much larger opening and bends every ray from one scene point back to one image point.

The pinhole model still works for a lens, because a well-made lens behaves, to a first approximation, as if all rays passed through one point. The differences between the ideal and the real lens are what the distortion terms of a calibration capture. The mrcal documentation is blunt about the ideal: longer lenses “tend to have roughly pinhole behavior, but no real-world lens follows this projection”.

The simplest model of a real lens is the thin lens: a single lens whose thickness is ignored. Rays that arrive parallel to the optical axis meet at the rear focal point F′. The distance from the lens to that point is the focal length, f.

How a thin lens forms an image Side view of a thin lens. An upright object stands at distance s in front of the lens. Three rays from its tip meet again behind the lens at distance s prime, where they form an inverted image. A ray parallel to the axis bends through the rear focal point F prime; a ray through the centre of the lens goes straight; a ray through the front focal point F leaves parallel to the axis. The focal length f is the distance from the lens to F prime. The distances obey 1/f = 1/s + 1/s prime. object image (inverted) F F′ s (object distance) s′ f (focal length) thin lens 1/f = 1/s + 1/s′
A thin lens brings the rays from each object point back together at one image point. The object distance s, the image distance s′ and the focal length f are tied by 1/f = 1/s + 1/s′. Focused at infinity, the sensor sits at f; focused closer, it sits a little further back.

For an object at distance s in front of the lens, the sharp image forms at distance s′ behind it, where:

1/f = 1/s + 1/s′
  • s: the object distance, from the lens to the object.
  • s′: the image distance, from the lens to the sharp image.
  • f: the focal length.

The image is inverted, and its size relative to the object, the magnification, is m = s′ / s.

Two consequences matter for cameras.

  1. Focused at infinity, the sensor sits exactly one focal length behind the lens. When s is very large, 1/s goes to zero and s′ = f.
  2. Focusing closer moves the image further back. The lens must move away from the sensor to stay sharp on a near object.

Real camera lenses have several elements, not one. They are described with the same equation by measuring distances from two principal planes instead of from a single thin lens, and the focal length on a datasheet is the effective focal length (EFL) of the whole assembly.

The two terms are easy to confuse.

  • Focal length is a property of the lens design. It sets the magnification and the field of view.
  • Focus distance is the object distance the lens is currently adjusted to render sharply. It is set by the lens-to-sensor spacing.

Worked example: how far the lens moves to refocus

Section titled “Worked example: how far the lens moves to refocus”

Our 2.0 mm lens, focused at infinity, has its image at s′ = 2.000 mm. Refocus it to 0.5 m (500 mm):

1/s′ = 1/2.0 − 1/500 → s′ = 2.0080 mm

The lens moves only 8.0 µm further from the sensor. At 1 m the shift is 4.0 µm, and at 0.3 m it is 13.4 µm. These distances are tiny, which is exactly why a small knock or a few degrees of temperature can refocus a small lens by accident. The lens effects page works through what this does to a calibration.

The pixel pitch is the distance from the centre of one pixel to the centre of the next, usually given in micrometres. The active area of the sensor is the pixel count times the pitch.

For our sensor:

Quantity Calculation Result
Active width 1280 × 3.0 µm 3.84 mm
Active height 800 × 3.0 µm 2.40 mm
Active diagonal √(3.84² + 2.40²) 4.53 mm

Do not derive the size from the format name. Lens maker Commonlands explains that “The “inch” in sensor format types is not a measurement unit. A “1/2.8 inch” sensor does not measure 1/2.8 inches in any dimension.” The names come from old television camera tubes. Take the width and height from the sensor datasheet.

A calibration does not report the focal length in millimetres. It reports it in pixels, because the camera measures positions in pixels:

f_px = f_mm / pixel_pitch_mm

For our camera: f_px = 2.0 mm / 0.003 mm = 666.7 px.

The calibration gives two values, fx and fy, one per axis. They can differ, for example when the pixel pitch is not the same along rows and columns. With square pixels they come out very close.

What f_px means in practice: a ray that arrives at a small angle θ off the optical axis lands about f_px · θ pixels from the principal point, with θ in radians. Near the image centre, our camera therefore spends 666.7 × π/180 = 11.6 pixels per degree.

Two cautions.

  • The datasheet focal length is nominal. The calibrated f_px is the measured value for that unit. Expect them to be close, not equal.
  • When the lens is focused closer than infinity, the pinhole “focal length” is really the image distance s′. That is why f_px changes when the focus changes.

For an ideal rectilinear lens, one that keeps straight lines straight, the angular field of view across a sensor dimension d is:

FOV = 2 · atan( d / (2f) )

Use the width for the horizontal field (HFOV), the height for the vertical field (VFOV) and the diagonal for the diagonal field (DFOV). Commonlands gives the same formula, for “an ideal rectilinear lens at a distant focus”.

For a fisheye lens with the equidistant projection (r = f · θ, explained on the projections page), the field across a dimension d is:

FOV = d / f (in radians; multiply by 180/π for degrees)

provided the lens’s image circle actually covers that dimension.

Lens on our 3.84 × 2.40 mm sensor HFOV VFOV DFOV
2.0 mm rectilinear 87.7° 61.9° 97.1°
1.6 mm rectilinear 100.4° 73.7° 109.5°
1.6 mm equidistant fisheye 137.5° 85.9° 162.2°

The same 1.6 mm focal length gives a far wider view as a fisheye, because a fisheye compresses the edges of the scene instead of stretching them. These are ideal figures. A real lens’s distortion moves them, so for a fisheye or any measurement work Commonlands advises: “use the lens’s measured projection data.”

For a rectilinear lens, the image radius is r = f · tan θ, so the number of pixels per degree grows toward the edge in proportion to 1 / cos²θ. For our 2.0 mm lens, a degree costs 11.6 px at the centre, 15.5 px at 30° off axis and 22.5 px at 44°, near the horizontal edge. An equidistant fisheye spends the same number of pixels per degree along the radius everywhere. This is one reason fisheye images “look distorted” and rectilinear images of wide scenes look stretched at the edges.

The aperture stop is the opening inside the lens that limits how wide a cone of light gets through. Seen from the front, through the elements in front of it, it appears as the entrance pupil. The f-number, N, is:

N = f / D

where D is the diameter of the entrance pupil. The Zeiss technical paper on depth of field puts it the same way: “The diameter of the entrance pupil is the focal length divided by the f-number k” (Zeiss writes k for the f-number).

For our lens at f/2.0, the entrance pupil is 2.0 / 2.0 = 1.0 mm across.

  • Light: the light reaching the sensor is proportional to 1/N². Each step of √2 in N (f/2, f/2.8, f/4, …) halves it.
  • Depth of field: a larger N gives a narrower cone of light and a deeper zone of acceptable sharpness.
  • Fixed apertures are common on small lenses. Commonlands notes that “Most M12 lenses run a fixed aperture”. On such a lens, the f-number is a design choice, not a setting.

Even a perfect lens cannot focus a point to a point. Light passing through a circular aperture spreads into an Airy pattern, whose central disc has a diameter of approximately:

Airy disc diameter ≈ 2.44 · λ · N

where λ is the wavelength. For green light (λ = 0.55 µm):

f-number Airy disc diameter
f/2.0 2.7 µm
f/2.8 3.8 µm
f/4.0 5.4 µm
f/8.0 10.7 µm

With 3.0 µm pixels, our f/2.0 lens is already close to the diffraction limit at the pixel scale. Stopping down a small-pixel camera for more depth of field soon costs sharpness. The diameter also scales with wavelength, so near-infrared light at 850 nm makes a disc about 1.5 times larger than green light.

A lens is exactly in focus at only one distance. A point nearer or further forms a small blur disc on the sensor instead of a point. The circle of confusion, c, is the largest blur disc you are willing to accept. The depth of field is the range of distances in which the blur stays below c.

Depth of field and the circle of confusion Side view of a lens focused at one distance. Light from a point at the focus distance converges exactly on the sensor. Light from a point at the near limit would converge behind the sensor, and light from a point at the far limit converges in front of it, so on the sensor each forms a small blur disc. The near and far limits are where that disc grows to the largest blur you accept, the circle of confusion c. Everything between them is the depth of field. Distances are not to scale. far limit focus distance near limit depth of field lens sensor blur disc on the sensor ≤ c inside the depth of field
A lens focuses exactly at one distance. Points nearer or further form a small blur disc on the sensor instead of a point. The depth of field runs between the near and far limits where that disc reaches the largest blur you accept, the circle of confusion c. Not to scale.

For a photograph, c is chosen from what a viewer can see in a print. For computer vision, choose c in pixels: one pixel (c = 3 µm here) is strict, and two pixels (c = 6 µm) is looser.

With focal length f, f-number N, circle of confusion c and focus distance s, the standard thin-lens formulas are:

H = f² / (N · c) + f (hyperfocal distance)
near = s · (H − f) / (H + s − 2f)
far = s · (H − f) / (H − s) (if s < H; otherwise far = infinity)

All lengths must be in the same unit. These are geometric approximations; diffraction and aberrations add blur on top.

The Zeiss paper adds a useful check, a relationship it says “applies to all apertures and distances”: the focus distance is the harmonic mean of the two limits, Dist = 2 · Near · Far / (Near + Far).

Hyperfocal distance and fixed-focus wearable cameras

Section titled “Hyperfocal distance and fixed-focus wearable cameras”

The hyperfocal distance, H, is the focus distance at which the far limit of the depth of field just reaches infinity. Focus there, and everything from about H/2 to infinity is acceptably sharp. Zeiss gives the same short form, H ≈ f² / (c · N), and notes that “the front end of the depth of field is located at half of the hyperfocal distance.”

This is why fixed-focus wearable cameras work. A short focal length makes H small, so one fixed focus setting covers nearly everything from arm’s length outward, and there is nothing to refocus during a recording.

Worked example: is a fixed-focus lens sharp for hand work?

Section titled “Worked example: is a fixed-focus lens sharp for hand work?”

Our 2.0 mm f/2.0 lens, with two choices of c:

Circle of confusion Hyperfocal distance H Focused at H: sharp from Focused at 0.5 m: sharp range
c = 6 µm (2 px) 0.335 m 0.17 m to infinity 0.20 m to infinity
c = 3 µm (1 px) 0.669 m 0.33 m to infinity 0.29 m to 1.98 m

Check with the harmonic-mean rule for the last cell: 2 × 0.286 × 1.976 / (0.286 + 1.976) = 0.500 m.

The reading depends on what the pipeline needs. Hands are typically within arm’s length of a head-worn camera. With the looser 2-pixel criterion, focusing at 0.5 m covers 0.20 m to infinity. With the strict 1-pixel criterion, no single focus covers 0.25 m to infinity; you choose between sharp hands and sharp far background. The calibration target must also sit inside the depth of field, or its corners will be soft.

The same tolerance on the sensor side is the depth of focus: how far the sensor (or the lens) can move along the axis before the blur exceeds c. For an object far away, it is approximately:

depth of focus ≈ ± N · c

For f/2.0 and c = 3 µm, that is ±6 µm. Compare it with the 8 µm the lens moved to refocus from infinity to 0.5 m above. It is the budget that temperature, shock and loose threads spend, and the lens effects page works through how fast.

In the pinhole model of a lens camera, the centre of projection is the centre of the entrance pupil: the image of the aperture stop seen from the front. It is usually somewhere inside the lens, not at the front glass, and in a wide-angle lens it can be well behind the front element.

This matters when you measure geometry by hand.

  • Extrinsics refer to the centre of projection. A stereo baseline measured between the front surfaces of two lenses is a different number from the calibrated baseline, unless the lenses are identical and mounted identically.
  • Field-of-view and distance calculations should start from the entrance pupil. Commonlands’s sizing guidance says to “measure distance from the effective viewpoint, the entrance pupil.”
  • Wide lenses are not perfectly central. In fisheye and very wide lenses, the entrance pupil shifts with the angle of the incoming ray, so rays from different directions do not all pass through one point. The mrcal documentation says the single-centre assumption “isn’t strictly true for real-world lenses”, and, describing its non-central CAHVORE model, that ignoring the non-central part “could be significant close to the lens.” For subjects at a normal working distance, the central models used by OpenCV, Kalibr and most other tools work well; the effect matters most for objects very close to the lens.
  • f_px is the physical focal length divided by the pixel pitch. Use it to sanity-check a calibration: a 2.0 mm lens on 3.0 µm pixels should calibrate near 667 px.
  • The field of view follows from f and the sensor size. Use it to check that a lens actually covers what the pipeline needs, before anyone builds a rig.
  • Fixed focus works because of the hyperfocal distance. Choose the focus setting from the working distances the pipeline needs, with c chosen in pixels.
  • Everything is measured from the entrance pupil, not the lens front.
  • Commonlands, CMOS sensor size chart: sensor format names, the rectilinear field-of-view formula and the entrance pupil as the viewpoint.
  • Commonlands, What is an M12 lens?: fixed apertures on M12 lenses.
  • Commonlands, Wide-angle lenses and fisheye camera lens distortion: rectilinear and equidistant image scale.
  • Nasse, H. H. (2010). Depth of field and bokeh. Carl Zeiss Camera Lens Division: entrance pupil, hyperfocal distance and the harmonic-mean rule.
  • mrcal lens models: pinhole behaviour of real lenses and non-central projection.
  • Hartley, R. and Zisserman, A. (2004). Multiple View Geometry in Computer Vision, 2nd ed. Cambridge University Press: the pinhole camera model.
  • Hecht, E. Optics. Pearson: the thin-lens equation, apertures, diffraction and the Airy disc (standard textbook physics).