Reinhard Global Tone Mapping
Implement Reinhard's global tone mapping operator to map High Dynamic Range (HDR) images to a displayable range while preserving local contrast. This technique is crucial in Computational Photography as it enables the display of HDR images on standard devices.
The concept of tone mapping is based on the idea of compressing the dynamic range of an image, which is the ratio of the brightest and darkest areas, to fit within the limited range of a display device. Tone mapping operators like Reinhard's apply a non-linear transformation to the image's luminance values, preventing saturation and preserving details. The transformation involves calculating the log-average luminance of the image, which represents the average brightness, and then scaling the luminance values based on a key value that controls the overall brightness.
To achieve this, the following steps are involved:
- Calculate the luminance of each pixel in the HDR image: .
- Compute the log-average luminance of the image: with a tiny (e.g. ) so black pixels don't break the logarithm.
- Scale the luminance values based on the key value and log-average luminance: .
- Apply the Reinhard compression function to the scaled luminance values.
- Restore colour by multiplying each pixel's R, G and B by the same ratio , and clip the result to .
Return an array of the same shape as the input, , with values in .
This technique is widely used in image and video processing applications.
Example
hdr = HDR image with values > 1.0 key = 0.18
LDR image with values in [0, 1]
- Take a image with two grey pixels: (a highlight) and (a shadow), with
key. Grey pixels have equal to their channel value, since the weights sum to 1: and . - Log-average luminance: . As a geometric mean, it isn't dragged up by one huge highlight the way an arithmetic mean is.
- Scale by : and .
- Compress: and .
- Each pixel's channels are multiplied by , giving and , shape as input.
- Notice: the inputs differ by , the outputs by about , so highlights are squeezed hardest. can never reach 1, so grey pixels stay below 1, but a strongly coloured pixel can push one channel past 1, which is what the final clip to handles.
Constraints
- hdr: HDR image (H, W, 3)
- key: Key value for exposure adjustment
- Return: Tone-mapped LDR image