Cameras & sensorsHow-to

Dark frame subtraction for fixed pattern noise: how many frames

How many lens-cap frames to average into a master dark for fixed pattern noise, why the corrected image can go negative, and whether to clip or rescale.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01What do you need before you can subtract a dark frame?
  2. 02How many frames should you average into a master dark?
  3. 03Which camera settings must match your production images?
  4. 04How do you capture the stack and build the master dark?
  5. 05Why does the corrected image span values like -172 to 194?
  6. 06Should you rescale the corrected image back to 0-255?
  7. 07When is a master dark not the whole correction?
  8. 08How do you verify the correction worked?
  9. 09When should you re-shoot the master dark?
  10. 10Questions

Subtracting a lens-cap frame from every image is the right instinct — it is how telescopes, scientific cameras and machine-vision pipelines have removed fixed pattern noise for decades. The single black frame your colleague subtracts is only half the method, though: it carries the offset pattern you want plus a full dose of random noise you do not. This guide gives the frame count that makes the master dark quieter than your image, the capture conditions that keep it valid, and the decision on what to do with negative values after subtraction. Ten minutes of arithmetic turns the trick from a subjective 'looks better' into a calibration you can defend in a validation report.

What do you need before you can subtract a dark frame?

You need a camera that outputs raw frames with its automatic corrections off, a lens cap or opaque cover, the exact exposure, gain and pixel format your production images use, and a script that averages at least 25 frames into one master dark.

Raw matters: if the camera already applies its own black-level or defect correction, you would subtract the pattern twice. Turn off auto exposure and auto gain too — a dark capture must not trigger an exposure hunt.

A dark frame is a measurement made with no photons. Cap the lens, and in a bright hall shroud the camera body as well: light leaks through mount gaps and paints a gradient you would otherwise bake into every corrected image. If your capped captures are already pinned at zero with no structure at all, that is an exposure or wiring fault rather than fixed pattern noise — the camera black image checklist sorts those causes in order.

The method works on any raw-output area scan camera, GigE or USB3, mono or color. A mono sensor keeps demosaicing out of the arithmetic; the MV-CS200-10UM is a solid starting point.

Area scan camerasHikrobot MV-CS200-10UM 20 MP Area Scan Camera, USB3.0, IMX183, 2nd Gen., MonoMV-CS200-10UM
Sensor format
1"
Lens mount
C-mount
Interface
USB3
Resolution
16-25 MP
$759.00View partBuild a system with it

How many frames should you average into a master dark?

Average 25 frames as a working floor and 100 when your signal sits within a few DN of the black level: the random noise left in the master falls as 1/√N, so 25 frames leave one fifth of a single frame's noise and 100 leave one tenth.

DN throughout means digital numbers, the raw pixel counts before any scaling.

Subtracting one capped frame swaps one noise draw for another. If image and dark carry the same temporal noise σ, the corrected image carries √(σ² + σ²) = σ√2 ≈ 1.41σ — a 41% penalty for calibrating. Averaging is the fix: temporal noise is uncorrelated from frame to frame and falls as 1/√N, while the fixed pattern is identical in every frame and survives the average untouched.

σ_master = σ_single / √N N = (σ_single / σ_target)²

Astrophotographers have shot stacked darks for decades, and the technique is documented as dark-frame subtraction; machine vision borrows it unchanged. It is the same 1/√N trade that lets a long-exposure average on a fixed-frame-rate camera beat one noisy frame: stack what repeats, average what does not.

Below about 16 frames the master's own noise stays comparable to a healthy sensor's read noise and the correction can come out net-negative in the darkest regions. Treat 25 as the floor and 100 as the point of diminishing returns — doubling N again buys only another ×1.4.

Which camera settings must match your production images?

Capture the dark with the same exposure time, gain, pixel format and sensor temperature as your production images, because each of those changes the offset pattern and noise you are about to bake into the master.

Exposure first: dark current piles up charge for every millisecond of integration, so the offset pattern rides on a dark pedestal 20x taller at 200 ms than at 10 ms. A master built at one exposure does not fit another. If the line runs one camera with two exposures per trigger, build one stack per exposure time.

Gain multiplies offsets and read noise together, so a master shot at 12 dB over-corrects images taken at 0 dB. Temperature moves the dark signal itself: silicon dark current roughly doubles for every 5 to 8 °C of rise, so shoot the stack after the camera has been running at production temperature, not cold off the shelf.

Log the exposure and gain the camera actually applied rather than the values you requested — the per-frame exposure and gain metadata check shows how to read them back for each frame. Keep the camera mounted while you calibrate: a camera stand such as the LS-MNT-0040 (700 mm column, 400 x 450 mm base) lets you cap the lens, re-shoot after any setting change and return the rig to the same geometry.

Camera standsMachine vision camera stand, professional slide-table type, height 700 mm, 400 x 450 mm base (LS-MNT-0040)LS-MNT-0040
Type
Camera stands
$629.00View partBuild a system with it

How do you capture the stack and build the master dark?

Cap or cover the optics, capture 25 to 100 raw frames at the production settings, average them in 32-bit float, and store the result as a float or 16-bit master you subtract from every production frame.

  1. Run the camera for 15-30 minutes so the sensor reaches the temperature it holds in production.
  2. Set the production exposure, gain and pixel format, and turn off auto exposure, auto gain and any in-camera defect or shading correction.
  3. Fit the lens cap and shroud the body if the room is bright.
  4. Capture five throwaway frames and discard them: after a settings change the first frames can still carry the old exposure or a settling bias — the first-frame-dark diagnosis explains the mechanism.
  5. Capture the stack — 64 frames in the worked example, 25 at minimum, 100 for low-light work. Accumulate the sum in a 32-bit float buffer and divide by the frame count once, at the end. Integer averaging of 8-bit frames rounds up to 0.5 DN into the master.
  6. Inspect before trusting: hot pixels and column streaks should sit where every raw dark frame shows them, and the histogram should sit within a few DN of the black level.
  7. Save the master as 32-bit float or 16-bit, with exposure, gain, date and camera serial in the file name.
  8. Correct each production frame in signed or float arithmetic — corrected = image − master — and clamp to the output range once, at the final write.

Steps 5 and 8 are where most implementations go wrong: average in float, round once.

Why does the corrected image span values like -172 to 194?

A spread like that means you subtracted a single unaveraged dark frame: the width is the dark frame's own temporal noise, not the pattern, and it reached at least 172 DN somewhere, which points at high gain, a hot sensor or an upstream rescale.

Most sensors ride on a black-level pedestal so that read noise does not fall off the bottom of the digitizer. The master removes the pedestal together with the pattern, so a pixel that truly received no light now averages 0 and wanders negative half the time. Negative outputs are the expected behaviour of noise around zero, not a defect of the method.

The width of the spread, though, is set by the temporal noise of the frame you subtracted. A modern machine-vision CMOS at unity gain shows roughly 1-3 DN of temporal dark noise in EMVA 1288-style measurements, and a single dark frame carries all of it. A ±172 DN excursion means the gain is amplifying noise tens of times, the sensor is running hot, or the black frame was rescaled upstream. Fix that before calibrating: dark subtraction cannot repair a frame whose noise already rivals the signal.

Quick test: capture 20 capped frames and compute the per-pixel standard deviation across the stack at a few positions. Around 1-4 DN is healthy; tens of DN point at gain or temperature.

Should you rescale the corrected image back to 0-255?

Never rescale: keep the corrected image in signed or float arithmetic and saturate negatives to zero only when you must deliver 8-bit, because mapping [-172, 194] back to [0, 255] lifts true black to about 120 DN and makes brightness meaningless.

Work through what the redraw computes: x maps to (x + 172) × 255/366 ≈ 0.70x + 120. A pixel that received no light lands at 120 DN — half the 8-bit range burned on an offset — and every threshold, ratio and background model downstream inherits it.

Saturate instead: clamp the corrected value to [0, 255] when writing the final 8-bit image. With a 64-frame master, σ_master = 0.5 DN, so negatives occur only where the true value is within about 1 DN of zero and clipping discards nothing measurable. Keep the signed image whenever a downstream stage computes differences, ratios or backgrounds near black level, because saturation biases dark measurements upward. Clipping hurts only when the master itself is noisy — with a single-frame dark, negatives span ±σ everywhere and clipping flattens real dark detail, one more reason the master must come from an averaged stack.

When is a master dark not the whole correction?

A master dark removes only the offset pattern (DSNU) and consistent hot pixels; per-pixel gain differences (PRNU) and photon shot noise survive it, so a uniformly lit scene still shows structure until you add a flat-field division.

Offsets are half the fixed pattern. Shoot a uniformly lit, texture-free target so the frame mean sits around 60-70% of full scale — 150-180 DN in 8-bit — compute flat = mean_flat_frame − master_dark, normalize by its mean, and divide each corrected image by that gain map.

Size the flat stack with the same √N rule. With a single flat frame at mean 180 DN and σ = 4 DN, the gain-map noise is 4 / 180 ≈ 2.2% per pixel — as large as the 1-3% PRNU typical of CMOS sensors. Average 25 flats and the estimate noise drops to 0.44%.

Photon shot noise survives both corrections and scales as √signal. The remaining levers are more light, frame averaging, binning or a cooled sensor: dark current halves for roughly every 5 to 8 °C of cooling.

How do you verify the correction worked?

Verify with numbers, not by eye: the pixel-to-pixel spread of a fresh dark stack's mean image should drop several-fold after subtraction, and the mean residual should sit within about 0.3 DN of zero.

Continue the worked example with DSNU σ = 3 DN and temporal σ = 4 DN. A fresh 25-frame dark stack produces a mean image whose pixel-to-pixel spread is √(3² + (4/√25)²) = √(9 + 0.64) ≈ 3.1 DN. After master subtraction the same measurement reads √(0.8² + 0.5²) = √0.89 ≈ 0.9 DN — about 3x lower, and what remains is pure temporal noise, not structure.

Second check: subtract the master from a fresh capped stack and average the residuals. With σ_master = 0.5 DN over 25 frames, the expected spread of that mean is 0.5 / √25 = 0.1 DN, so the mean residual should sit within about ±0.3 DN of zero. A mean of +2 DN means exposure or temperature drifted since the master was built.

Third check: correct a uniformly lit frame and compare row and column means. A column brighter than its neighbours by more than the residual noise is column fixed pattern the offset map cannot reach — that belongs to the flat-field step.

Three mistakes account for most failed calibrations:

  • Building the master on a cold camera and running it warm on the line.
  • Integer averaging of 8-bit frames, which bakes up to 0.5 DN of rounding into the master before subtraction even starts.
  • One master shared across two camera units, even of the same model.

When should you re-shoot the master dark?

Re-shoot the master whenever the exposure, gain, pixel format, camera unit or sensor temperature changes: the pattern is fixed in space, but its amplitude moves with every one of those, and a stale master biases each image until it is rebuilt.

Work through the list whenever anything in the chain changes:

  • Exposure or gain changed — one new stack per setting combination, including the two-exposure case.
  • Ambient temperature moved by more than about 5 °C — re-shoot at the new steady state.
  • Camera replaced — per-sensor masters never transfer, same model or not.
  • Pixel format changed between 8-bit and 12-bit pipelines — the pattern is the same in electrons, but rebuild in the format you deploy so the scaling matches end to end.

If you are choosing hardware for a pipeline that needs raw frames and stable gain, the camera finder filters models by interface, shutter and resolution, and the camera configurator pairs a camera with its lens and light. More camera-side reading lives on the cameras topic page, and the contact page reaches the applications team when you want a second pair of eyes on a calibration plan.

Questions

Does dark frame subtraction remove photon shot noise?

No. A master dark removes the per-pixel offset pattern (DSNU) and consistent hot pixels only. Photon shot noise is random and scales with the square root of the signal, so a feature averaging 10,000 DN still carries about √10000 = 100 DN of shot noise after perfect calibration. Reduce it with more light, binning or frame averaging.

Can I share one master dark between cameras of the same model?

No. Fixed pattern noise is a property of the individual sensor die: two units of the same model have different offset maps, hot pixels and column defects. Build one master per camera serial, and rebuild it after a camera swap, an exposure or gain change, or a shift of more than a few degrees in operating temperature.

Should the master dark be stored as 8-bit, 16-bit or float?

Store it as 32-bit float, or at least 16-bit. An 8-bit master quantizes every pixel's offset to whole DN and adds up to ±0.5 DN of quantization error to each corrected image — the same order as the noise you averaged 64 frames to reduce. Round to integers once, at the final output stage.

Do hot pixels survive the frame averaging?

Pixels that are hot in every dark frame survive the average, which is what you want: subtraction removes them from production images. A one-off event in a single frame would drag the mean, so compare the master against individual frames for isolated spikes, re-shoot the stack if you find one, or use a median instead of a mean.

Why does the master dark stop fitting after a season change?

Dark signal rises with sensor temperature, roughly doubling every 5 to 8 °C in silicon. A master captured in a 20 °C room underestimates the offset on a line running at 40 °C, so corrected images keep a faint positive haze. Shoot the replacement stack after the camera has warmed to its real operating temperature.

Is a dark frame the same as a background or flat-field image?

No. A dark frame calibrates the sensor itself and is captured with no light reaching it. A flat field is captured through the lens against a uniform bright target and corrects per-pixel gain differences plus lens shading. A background image of the lit scene corrects uneven illumination. Use the dark first, then the flat; the background replaces neither.