This Jupyter notebook reconstructs HDR images from Apple's SDR HEIC images and their associated gain maps.
- Go to https://mybinder.org/
- Enter the GitHub repository URL
- Click "launch"
The notebook implements Apple's gain map formula:
L_hdr = L_sdr × (1 + (Headroom - 1) × GainMap)
Where:
L_sdris the SDR (Standard Dynamic Range) imageGainMapis the additional brightness informationHeadroomis extracted from XMP metadata (how much brighter HDR is vs SDR)
- Input: Display P3 color space (Apple devices)
- Linearization: Remove gamma encoding
- Gain Application: Apply the formula above
- Color Adaptation: Convert to BT.2020 using Bradford chromatic adaptation
- PQ Encoding: Apply Perceptual Quantizer transfer function
- Output: 16-bit PNG with cICP metadata chunk
- Format: 16-bit PNG
- Color Primaries: BT.2020 (ITU-R Recommendation BT.2020)
- Transfer Function: PQ/ST.2084 (Perceptual Quantizer)
- Reference White: 203 nits
- Peak Brightness: 1000 nits
- Metadata: cICP chunk for HDR signaling
- Ensure you've created the
data/folder - Verify your files are named exactly as expected
- Check file extensions are correct (.HEIC, .png)
- On mybinder, dependencies should install automatically
- If running locally, use:
pip install -r requirements.txt
- The gain map PNG should contain XMP metadata with headroom value
- If missing, default headroom of 1.0 is used (no HDR enhancement)
This notebook is provided for educational purposes.