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.
- Scale the luminance values based on the key value and log-average luminance.
- Apply the Reinhard compression function to the scaled luminance values.
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]
- Compute luminance from RGB
- Calculate log-average luminance
- Scale by key/log_avg
- Apply L/(1+L) compression
- Reconstruct color
Constraints:
- hdr: HDR image (H, W, 3)
- key: Key value for exposure adjustment
- Return: Tone-mapped LDR image
More from CV: Computational Photography
- Background Knowledge
In HDR imaging, scenes often have luminance values that span several orders of magnitude, while typical displays (and 8-bit images) can only show a limited dynamic range (e.g., 0β255). Tone mapping operators (TMOs) compress this large dynamic range into a smaller, displayable range while trying to preserve important visual properties like contrast and detail. Global TMOs apply the same mapping to every pixel based only on its luminance value; local TMOs consider spatial neighborhoods.
Reinhardβs global tone mapping operator is a classic, simple TMO. The idea is to first normalize scene (world) luminance by a βkeyβ value that controls overall brightness, then pass it through a nonlinear curve:
- Key scaling: L=LΛaββ Lwβ
- Tone mapping: Ldβ=1+LLβ
Here LΛ is the log-average luminance of the scene, which is more robust than a simple arithmetic mean for HDR data. The final Ldβ is in (0,1) and can be mapped to display intensities.
- Algorithm / Approach
The general pattern for this problem:
- Extract luminance from the HDR RGB image to get Lwβ(x,y).
- Compute log-average luminance LΛ over all pixels.
- Apply key scaling with a given parameter a (e.g., 0.18) to get scaled luminance L.
- Apply Reinhard curve Ldβ=1+LLβ to compress dynamic range.
- Re-apply color: scale original RGB channels so that their new luminance matches Ldβ.
- Clamp and convert to the desired output range (e.g., 0β255 uint8).
This is a straightforward per-pixel mapping with an initial global statistic (LΛ).
- Step-by-Step Strategy
Assume input is an HDR image img_hdr in floating point RGB.
- Compute luminance channel Use standard Rec.709 coefficients:
R = img_hdr[..., 0]
G = img_hdr[..., 1]
B = img_hdr[..., 2]
Lw = 0.2126 * R + 0.7152 * G + 0.0722 * B
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.