Skip to content

Tone mapping

Fact Value
Also called Reinhard tone mapping, Drago tone mapping, Mantiuk tone mapping, HDR tone mapping
Status Implemented and tested
Family Enhancement, illumination and color
Engine Science engine
Type Nonlinear, point, tone mapping
Output Image
Operator shown as algorithm (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/tone.py, tone_mapping
Operator code engine/src/pixelnexus_engine/filters/tone.py, tone_mapping_representation
Packages OpenCV

Overview

Tone mapping compresses a wide range of brightness into the range a screen can show. This filter offers three classic operators from OpenCV. Reinhard and Devlin model the photoreceptors of the eye. Drago et al. use an adaptive logarithm. Mantiuk et al. compress contrast in the gradient domain. An ordinary 8-bit image has a small range already, so here the operators mostly reshape the tone curve and the local contrast. The filter runs in the PixelNexus engine.

Four panels. The input has a dark left half with three faint squares, a gray ramp in the middle and a light right half with three faint squares. With Reinhard, Drago and Mantiuk, the dark ground turns black and its squares become clear gray squares. The light ground turns almost white, and its squares almost vanish. Four panels. The input has a dark left half with three faint squares, a gray ramp in the middle and a light right half with three faint squares. With Reinhard, Drago and Mantiuk, the dark ground turns black and its squares become clear gray squares. The light ground turns almost white, and its squares almost vanish.
A dark half and a bright half, each with squares 10 levels apart, and a ramp between. Then the Reinhard, Drago and Mantiuk operators with their defaults.

How it works

  1. Decode the 8-bit values to linear light with the sRGB curve.
  2. Apply the chosen operator.
  3. Stretch the result and apply the gamma.
  4. Scale to 8 bits.

Mathematical foundation

\[ L = \text{sRGB}^{-1}\!\left(\frac{I}{255}\right), \qquad \text{out} = \left(\frac{T(L) - \min T}{\max T - \min T}\right)^{1/\gamma} \]

The formula shows the default parameter values.

where

  • \(L\): Linear light from 0 to 1
  • \(T\): The tone mapping operator
  • \(\gamma\): The display gamma

The 8-bit values are decoded to linear light L, since the operators expect radiance. T is the chosen operator. Reinhard and Devlin map each value with a photoreceptor curve I / (I + (f I_a)^m). The adaptation level I_a mixes the pixel, its channel and the image mean. Drago et al. take a logarithm whose base changes with brightness. The bias sets how. Mantiuk et al. turn the log luminance into a pyramid of gradients, multiply the contrast response by the scale, and rebuild the image. OpenCV then stretches T from its minimum to its maximum and applies 1 / gamma.

Kernel or operator

There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Operator operator Reinhard and Devlin Reinhard and Devlin, Drago, Mantiuk The tone mapping operator.
Gamma gamma 2.2 0.5 to 4 OpenCV raises the stretched result to 1 / gamma. OpenCV uses 1. 2.2 is our choice, close to the sRGB curve the input was decoded with.
Intensity intensity 0 -8 to 8 For Reinhard only. The brightness of the result, from -8 to 8. OpenCV uses 0.
Light adaptation lightAdapt 1 0 to 1 For Reinhard only. 1 adapts to each pixel, 0 to the mean of the image. OpenCV uses 1.
Color adaptation colorAdapt 0 0 to 1 For Reinhard only. 1 adapts each channel on its own, 0 adapts to the luminance. OpenCV uses 0.
Saturation saturation 1 0 to 2 For Drago and Mantiuk. The color saturation of the result. OpenCV uses 1.
Bias bias 0.85 0.5 to 1 For Drago only. The bias b of the adaptive logarithm. The OpenCV documentation says 0.7 to 0.9 usually work best, and OpenCV uses 0.85.
Contrast scale scale 0.7 0.1 to 1 For Mantiuk only. The factor that the contrast response is multiplied by. OpenCV uses 0.7.

Implementation

tone_mapping in engine/src/pixelnexus_engine/filters/tone.py decodes the 8-bit values with the sRGB curve, since the operators expect linear light. It passes the image to OpenCV in BGR order as float32, and scales the result from 0 to 1 back to 8 bits. OpenCV's operators end by stretching their result from its minimum to its maximum and raising it to 1 / gamma, as its source shows.

Worked example

Operator Dark ground Dark square step Bright ground Bright square step
Input 20 10 235 10
Reinhard 0 106 252 3
Drago 0 88 253 2
Mantiuk 2 88 250 5

The image of the figure. The dark ground is 20 and its squares 30. The bright ground is 235 and its squares 245. A step is the square minus its ground.

All three operators spread the dark squares apart, from a step of 10 to one of 88 to 106. The bright squares nearly vanish, with a step of 2 to 5. On linear light the dark values are small, and each operator lifts them most. The final stretch then sends the darkest ground to black or almost black.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(N)\)

N is the number of pixels.

Artifacts and limitations

Limitations

  • An 8-bit image has little dynamic range, so the effect is smaller than on true HDR data.
  • Results differ in brightness, since each operator stretches its own way.

Artifacts

  • Halos around strong edges with Mantiuk at low contrast scale.
  • Washed out colors with Drago at high bias.

Tests

The sRGB curve must match its formula. Each operator must equal OpenCV's own call on the decoded image, and the alpha must stay. Each representation must have its three stages.

References

  • Reinhard, E., and Devlin, K. Dynamic range reduction inspired by photoreceptor physiology. IEEE Transactions on Visualization and Computer Graphics 11(1), 13 to 24, 2005. DOI 10.1109/TVCG.2005.9.
  • Drago, F., Myszkowski, K., Annen, T., and Chiba, N. Adaptive logarithmic mapping for displaying high contrast scenes. Computer Graphics Forum 22(3), 419 to 426, 2003. DOI 10.1111/1467-8659.00689.
  • Mantiuk, R., Myszkowski, K., and Seidel, H.-P. A perceptual framework for contrast processing of high dynamic range images. ACM Transactions on Applied Perception 3(3), 286 to 308, 2006. DOI 10.1145/1166087.1166095.
  • OpenCV documentation, cv::TonemapReinhard, cv::TonemapDrago and cv::TonemapMantiuk.