Conversion
hdrconv.convert
HDR conversion algorithms.
This module provides functions for converting between HDR formats and applying color space and transfer function transformations:
- Gainmap conversion:
gainmap_to_hdr,hdr_to_gainmap - Apple HEIC conversion:
apple_heic_to_hdr - Color space conversion:
convert_color_space - Transfer functions:
apply_pq,inverse_pq
apple_heic_to_hdr(data)
Convert Apple HEIC gain map data to linear HDR.
Applies Apple's proprietary gain map formula to reconstruct the HDR image from the SDR base and single-channel gain map.
The reconstruction formula is
hdr_rgb = sdr_rgb * (1.0 + (headroom - 1.0) * gainmap)
Where all values are in linear light space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
AppleHeicData
|
AppleHeicData dict containing:
- |
required |
Returns:
| Type | Description |
|---|---|
HDRImage
|
HDRImage dict with the following keys: |
HDRImage
|
|
HDRImage
|
|
HDRImage
|
|
HDRImage
|
|
Note
The gain map is upscaled from 1/4 resolution using bilinear interpolation. Both base image (sRGB transfer) and gain map (Rec. 709 transfer) are linearized before applying the formula.
See Also
read_apple_heic: Read AppleHeicData from HEIC file.
Source code in src/hdrconv/convert/apple.py
gainmap_to_hdr(data)
Convert ISO 21496-1 Gainmap to linear HDR image.
Applies the gainmap to the baseline image to reconstruct the alternate (HDR) representation using the ISO 21496-1 formula:
- G' = (G^(1/gamma)) * (max - min) + min
- L = 2^G'
- HDR = L * (baseline + baseline_offset) - alternate_offset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GainmapImage
|
GainmapImage dict containing baseline, gainmap, and metadata. |
required |
Returns:
HDRImage dict with the following keys:
- data (np.ndarray): Linear HDR array, float32, shape (H, W, 3).
- transfer_function (str): Always 'linear'.
Note
The baseline image must be in linear light space (not gamma-encoded). The caller is responsible for applying EOTF conversion before calling this function if the input is gamma-encoded (e.g., sRGB).
See Also
hdr_to_gainmap: Inverse operation, create gainmap from HDR.
Source code in src/hdrconv/convert/gainmap.py
hdr_to_gainmap(hdr, baseline=None, icc_profile=None, gamma=1.0)
Convert linear HDR image to ISO 21496-1 Gainmap format.
Creates a gainmap by computing the log2 ratio between HDR and SDR images. If baseline is not provided, generates one by clipping HDR to [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdr
|
HDRImage
|
HDRImage dict with linear HDR data in any supported color space. |
required |
baseline
|
Optional[ndarray]
|
Optional pre-computed baseline (SDR) image. If None, generated by clipping HDR to [0, 1]. Expected format: float32, shape (H, W, 3), range [0, 1]. |
None
|
icc_profile
|
Optional[bytes]
|
Optional ICC profile bytes to embed in output. Should match the specified color_space. |
None
|
gamma
|
float
|
Gainmap gamma parameter for encoding. Higher values compress highlights. Default: 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
GainmapImage
|
GainmapImage dict containing: |
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
Note
Uses fixed offsets of 1/64 for both baseline and alternate to avoid division by zero in dark regions.
See Also
gainmap_to_hdr: Inverse operation, reconstruct HDR from gainmap.write_21496: Write GainmapImage to ISO 21496-1 JPEG.
Source code in src/hdrconv/convert/gainmap.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |