Conversion
hdrconv.convert
HDR conversion algorithms.
This module provides functions for converting between HDR formats:
- Gainmap conversion:
gainmap_to_hdr,hdr_to_gainmap - Apple HEIC conversion:
apple_heic_to_hdr
Transfer function encoding/decoding (e.g. PQ) is handled with the colour
package, e.g. colour.eotf(data, 'ITU-R BT.2100 PQ') and
colour.eotf_inverse(data, 'ITU-R BT.2100 PQ') as shown in examples/.
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, gainmap_resize_method='shepard')
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 |
gainmap_resize_method
|
GainmapResizeMethod
|
Method used when gainmap and baseline dimensions differ.
|
'shepard'
|
Returns:
HDRImage dict with the following keys:
- data (np.ndarray): Linear HDR array, float32, shape (H, W, 3).
- transfer_function (str): Always 'linear'.
- icc_profile (bytes | None): ICC profile describing the working
color space of the reconstruction: baseline_icc when
use_base_colour_space is True, otherwise gainmap_icc when the
baseline was converted to the alternate space (falling back to
baseline_icc if the conversion was skipped or failed).
See Also
hdr_to_gainmap: Inverse operation, create gainmap from HDR.
Source code in src/hdrconv/convert/gainmap.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
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 in LINEAR light — do not pass sRGB/gamma-encoded data (the sRGB encoding is applied internally when storing the baseline). 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 describe the color space of |
None
|
gamma
|
float
|
Gainmap gamma parameter for encoding. Higher values compress highlights. Default: 1.0. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
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
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |