Set Brightness to lift the black level and Gamma to 2.2, and the pixel you expected at 20 DN comes back near 60-80 DN. Nothing is broken: the camera adds the offset in the linear domain first, and the gamma stage then encodes the sum. This guide gives the order of operations, the formula that predicts the combined pixel value, a worked example with the arithmetic shown, and the decision rule for when a measurement needs gamma switched off. It is written for anyone setting acquisition features for thresholding, low-light detection, or any inspection that reads pixel values as numbers.
The order of operations: offset first, gamma second
In a machine-vision camera the stages run in a fixed order: sensor charge, analog gain, ADC, digital corrections, then the gamma look-up table near the output. The Brightness control is a digital offset added after the ADC. GenICam's SFNC standard names this feature BlackLevel; some cameras present the same register as Brightness. Because gamma sits after that adder, it never sees black plus 20. It sees 20 and encodes it.
The pipeline-order guide on analog gain, ADC, then digital gamma covers the stages before this point. The ordering explains three observations you can reproduce on any camera:
- Gamma 2.2 with no offset: a true black pixel stays 0, because zero raised to any power is zero.
- Brightness only, gamma 1: the pixel lands exactly on the offset you set, at 20 DN in the example below.
- Both together: the pixel lands on the encoded offset, well above 20, because gamma multiplies — it does not add.
The ideal formula, and what it predicts
The ideal gamma stage follows a power law:
with V_out the 8-bit output, V_in the linear value after the offset, and V_max = 255 for RGB8. Display-oriented encoding exists because it spends the 256 codes the way eyes weight brightness: shadows get far more codes than a linear scale would give (the gamma correction overview on Wikipedia has the background). The consequence for your pixel values: the smaller the linear value, the larger the lift. A 20 DN floor maps to 80 DN at γ = 2.2, a 4.0× lift. A 200 DN mid-tone maps to 149 DN, a 0.75× reduction. Whatever you add near black, gamma amplifies the most.
To read encoded values back into linear DN, invert the same law:
Worked example: a 20 DN offset through gamma 2.2
Inputs, and where each comes from:
- Sensor pixel at true black: 0 DN linear.
- Brightness register: 320 counts. This camera family specifies the offset at the ADC's 12-bit depth, so at 8-bit output the same offset is 320 ÷ 16 = 20 DN, because 4096 ÷ 256 = 16. The raw-versus-display depth mismatch is its own trap; see black level offset in raw 12-bit images and raw10 and raw12 sensor modes.
- Gamma: 2.2, output RGB8, V_max = 255.
- Stage order: offset added before the gamma table.
The rule in words: add the offset in the linear domain, normalize by full scale, raise to 1/γ, scale back to 255. The arithmetic:
- Linear pixel after the offset: 0 + 320 counts, which is 20 DN at 8-bit scale (320 ÷ 16).
- Normalize: 20 ÷ 255 = 0.0784.
- Encode: 0.0784^(1/2.2) = 0.0784^0.4545 = 0.3144.
- Scale: 0.3144 × 255 = 80.2. The ideal prediction is 80 DN.
A camera whose application note states a sixteen-section piecewise-linear approximation for its 8-bit modes measured this exact case at 60-62 DN. The ideal formula overshoots the measured value by 18-20 DN, about 23-25% at this input.
Decision: with gamma on, treat the power law as an upper estimate for shadow values. If the number must be exact — a threshold at 90 DN, a radiometric reading — set gamma to 1 or measure the table with the two-frame check below. If gamma stays at 2.2 for display, budget 60-80 DN for a 20 DN offset and calibrate the final figure on the camera you own.
Why the measured value lands below the ideal
The shortfall is the look-up table, not the exponent. No camera computes 0.0784^0.4545 per pixel in real time; the gamma stage reads a stored table, and the table's construction decides the shadow values.
- A 256-entry table rounded from the exact power law lands within 0.2 DN of ideal: input 20 reads 80.
- A sixteen-section chord fit anchored on the ideal curve at 16 DN steps predicts 79 DN at input 20. The segment endpoints are 72.5 and 99.3; input 20 sits one quarter into the segment, and 72.5 + 0.25 × 26.8 = 79.2.
- A table built with coarser 12-bit arithmetic, fewer shadow points, or a vendor's own segment placement can sit far lower. The measured 60-62 DN is about 23% under ideal.
So the exponent predicts the trend, and the implemented table decides the value. Two cameras set to the same γ = 2.2 can differ by tens of DN in the shadows while matching within a DN or two above mid-scale. That is why the recipe ends at a measurement, not at the formula: run the two-frame check once, and the table is yours.
Inverting it: from the encoded value back to linear
Apply the inverse law V_in = 255 × (V_out/255)^γ to decode. For γ = 2.2:
| Encoded DN (V_out) | Linear DN (V_in), ideal inverse |
|---|---|
| 20 | 0.9 |
| 60 | 10.6 |
| 80 | 20.0 |
| 128 | 56 |
| 200 | 149 |
The 80 DN row is the round trip of the worked example: encoded 80 decodes to the 20 DN offset you set. The 60 DN row shows the table again: that camera's actual output decodes to 10.6 DN under the ideal inverse, not to the 20 you set. When you need linear values from an encoded stream, decode with your camera's measured pairs from the two-frame check; the exponent alone recovers shadows only for a camera that truly implements the plain power law.
What the lift does to noise and thresholds
Gamma encodes your noise floor with the same curve as your signal. At the 20 DN point on the ideal curve, two numbers:
- The DC value lifts 4.0×: 20 DN in, 80 DN out.
- The incremental slope is dV_out/dV_in = (1/γ) × (V_in/255)^(1/γ − 1) = 0.4545 × 4.009 = 1.82 DN per DN, so ±3 DN of read noise leaves the gamma stage as ±5.5 DN.
A smaller offset is also cheaper than a bigger gamma. The offset lifts only what you add; gamma lifts everything near black, signal included.
When to set gamma to 1, and when gamma helps
Set gamma to 1 whenever pixels are data: thresholding, blob sizing, radiometry, photometric stereo, defect contrast near black level, and any frame that feeds a classifier — train and run with the same gamma, or the shadows shift under the model. Keep gamma at 2.2 where pixels go to a person. An operator's live view of a dark scene gains real shadow contrast, which is what the encoding spends its codes on. If the image still looks dark, your viewer may be applying its own encoding to a linear feed; that split is its own subject, covered in linear RGB vs sRGB: image brightness in script vs viewer.
Per case: measurement stream, gamma 1 and the smallest offset the scene allows. Preview stream, gamma 2.2 is fine and nothing should be measured from it. Detection with a fixed threshold: one setting, calibrated once, never changed silently.
The two-frame check before you trust any prediction
Set every acquisition feature deliberately, before the stream starts; the initialization-order guide on set manual exposure before streaming shows the sequence. Then run the check:
- Expose a uniform gray target so the shadow region sits near 20 DN at gamma 1.
- Frame one: gamma 1, offset 320 counts (the working offset). Record the mean DN of a center patch — this is the true linear input.
- Frame two: gamma 2.2, everything else identical. The same patch now reads the encoded output.
- The pair is one point of your camera's table. Repeat at 5 to 10 gray levels and you can predict the combined value for any offset in that range.
The test runs on any area scan camera that lets you set gamma and the black-level offset from your SDK. For a bench check, a 2.5 MP GigE camera with a global shutter is all the hardware it takes:
- Sensor format
- 1/1.7"
- Lens mount
- C-mount
- Interface
- GigE
- Resolution
- Up to 3 MP
If you are shortlisting hardware for a station where you will own these settings, the area scan cameras category is the place to filter; a 12 MP GigE model and a 20 MP USB3 mono model bracket the common resolutions:
- Sensor format
- 1/1.7"
- Lens mount
- C-mount
- Sensor format
- 1"
- Lens mount
- C-mount
Next step: decide which stream measures and which one displays, set gamma per stream, and run the two-frame check once on the camera you own. To spec hardware around these settings, start at the camera finder or the camera step of the configurator. The cameras topic page collects the rest of the pipeline guides.
Questions
Does gamma lift a completely black pixel?
Not on its own. Zero raised to any power stays zero, so with gamma 2.2 and no offset a true black pixel still reads 0. The lift needs a nonzero linear value from a brightness offset, dark current or stray light. A 20 DN offset becomes about 80 DN at gamma 2.2 on the ideal curve, and 60-62 DN on a camera with a sixteen-section table, so zero the offset when you need reference black.
Is camera gamma the same as the sRGB curve?
No. sRGB encoding uses a short linear toe — below 0.04045 normalized the slope is 12.92 — then a power of 2.4 above it. A camera set to gamma 2.2 usually applies a plain power law, or its look-up table approximation, over the whole range. Mid-scale values match closely; deep shadows differ, so calibrate against your camera's measured table rather than the sRGB formula.
What gamma should I use for measurements?
Gamma 1. Any measurement that reads DN — thresholds, blob sizing, radiometry, photometric stereo, defect contrast near black level — assumes output proportional to sensor signal. Gamma 2.2 multiplies shadow values fourfold and a look-up table bends them further. Leave gamma for the operator's preview and keep the measurement stream linear; the fourfold shadow lift near a threshold is exactly the error you cannot see coming.
Why does my Brightness register need 320 to add 20 DN?
The register is scaled at the ADC depth, not at the 8-bit image. From 8-bit DN to 12-bit counts the factor is 2^(12-8) = 16, so a 20 DN offset is written as 320. On a 10-bit register the factor is 4, so the same 20 DN target is 80. Match the register's stated scale before you type the value.
How do I measure my camera's real gamma curve?
Two frames on a uniform or stepped target, everything else fixed. Frame one at gamma 1 gives the true linear input; frame two at your working gamma gives the encoded output; each gray patch is one point of the camera's look-up table. Ten to sixteen gray levels between 5 and 80 DN characterize the shadow region well enough to predict any combined value in that range.


