To solve this problem, you only need to apply a simple mathematical operation to each luminance value, but it helps to understand the photographic meaning behind it.
1. Background Knowledge
In HDR imaging, each pixel often stores a luminance value L in a physically meaningful or wide dynamic-range space (often floating point). These values can span many orders of magnitude (from dark shadows to bright highlights), so we adjust them before compressing them with a tone-mapping operator.
Exposure value (EV) or “stops” comes from photography: changing exposure by +1 stop doubles the amount of light reaching the sensor; -1 stop halves it. Mathematically, this corresponds to multiplying luminance by a power of 2:
Ladjusted=L⋅2exposure
This simulates changing shutter speed, aperture, or ISO in a virtual camera before tone mapping.
2. Algorithm / General Approach
The pattern here is:
- Treat exposure compensation as a global scale factor applied uniformly to all luminance values.
- Compute this scale factor as s = 2^{\text{exposure}}.
- Multiply every HDR luminance value by s.
This is just an element-wise transformation over an array (or image) of luminance values.
3. Step-by-Step Strategy
- Input parsing
- Read the HDR luminance values (likely as a 2D array or 1D list of floats).
- Read the exposure value (a float, can be positive, negative, or zero).
- Compute the scaling factor
scale = 2 ** exposure
or, in many languages, pow(2.0, exposure).
- Apply exposure adjustment
- For each luminance value L[i]:
L_adjusted[i] = L[i] * scale
- Return / store result
- Output the adjusted luminance values in the same shape/format as the input.
Example (Python-style pseudocode):
def adjust_exposure(luminance, exposure):
scale = 2.0 ** exposure
return [L * scale for L in luminance]
For an image, the same idea applies but over a 2D array.
4. Common Pitfalls
- Using the wrong base: The formula uses base 2, not base 10. It must be 2^{\text{exposure}}, not 10^{\text{exposure}}.
- Integer arithmetic: Make sure you are using floating-point for luminance and exposure; integer math will break fractional exposures and precise scaling.
- Overflow/underflow: Extreme exposure values on very large/small luminance values can overflow or underflow; not usually a concern in an easy problem, but good to be aware of.
- Modifying in place incorrectly: If the platform expects you to return a new array, don’t overwrite the input unless allowed.
5. Time & Space Complexity
Let N be the number of luminance values (pixels):
- Time complexity: O(N) — you do a constant amount of work per pixel (one multiply).
- Space complexity:
- O(N) if you create a new array for the adjusted luminance.
- O(1) extra space if you modify the array in place.