HDR data visualization for the browser, from numpy arrays.
Project description
hdrviz
Data visualization in HDR
About
hdrviz is a minimal Python library (~250 lines) that renders 2D numpy arrays as PQ Rec2020-tagged PNGs for HDR-capable browsers.
If your data has more dynamic range than 8-bit color can show — astrophotography, fluorescence microscopy, fractals, log-magnitude FFTs, density maps — hdrviz lets displays render the better contrast that's actually in the data.
This library is an encoder plus a reference notebook widget. For axes, colorbars, channel mixing, pan/zoom — compose with matplotlib, plotly, or viv.
Install
pip install hdrviz
Quick start
import numpy as np
import hdrviz as hv
data = np.random.RandomState(0).rand(400, 600)
widget = hv.imshow(data, cmap="inferno-hdr", peak_nits=4000)
widget # display in a notebook
Lower-level API
imshow is a convenience wrapper over a three-step pipeline: apply a colormap to map normalized data to RGB linear-light luminance in cd/m² (nits), run the SMPTE ST 2084 inverse EOTF (the "PQ encoding," via colour-science), and write a PNG with an embedded PQ Rec2020 ICC profile that browsers know how to composite in extended dynamic range.
from hdrviz import hdr_colormap, encode_hdr_png
norm = (arr - arr.min()) / (arr.max() - arr.min())
rgb_nits = hdr_colormap(norm, cmap_name="inferno-hdr", peak_nits=4000)
png_bytes = encode_hdr_png(rgb_nits) # PQ Rec2020-tagged PNG
PNG bytes are the deliverable. Serve them from a backend, write them to disk, embed them in custom HTML — anywhere that wants "an HDR image from a numpy array."
API surface
| Symbol | Purpose |
|---|---|
encode_hdr_png(rgb_nits, icc_profile) |
PNG encoding from linear-light RGB nits |
linear_nits_to_pq(rgb_nits) |
SMPTE ST 2084 inverse EOTF (wraps colour-science) |
hdr_colormap(norm, cmap_name, peak_nits) |
apply a named HDR colormap |
extract_icc_from_png(png_bytes) |
pull an ICC profile from a PNG's iCCP chunk |
to_data_url(png_bytes) |
inline embedding helper |
COLORMAP_LIBRARY |
seven HDR-aware colormaps (fire-purple, ice, twilight-burst, matrix-green, ember, viridis-hdr, inferno-hdr) |
DEFAULT_PQ_REC2020_ICC |
bundled ICC profile (~9 KB, "Rec2020 Gamut with PQ Transfer") |
imshow(arr, cmap, peak_nits, ...) |
quickstart wrapper that returns an HDRImage |
class HDRImage(anywidget.AnyWidget) |
reference display widget with an SDR-clamp toggle |
What hdrviz isn't
- Plotting framework with axes, ticks, labels, colorbars — compose with matplotlib
- Multi-channel mixing, contrast sliders, pan/zoom, multi-resolution tiling — compose with viv, ideally with HDR PNG tiles encoded by
hdrviz - Animated or video HDR — waits for
configureHighDynamicRange()to ship in stable Chromium
Demo notebook
notebook.py is a marimo notebook with introducing the HDR data visualization idea:
- A widget that checks your browser's HDR capabilities
- An interactive Mandelbrot explorer with HDR colormaps and click-to-zoom
- The Horsehead Nebula photographic plate from the astropy tutorials archive
- A fluorescence-microscopy frame from
scikit-image.data.cells3d, where the membrane channel's ~150× native dynamic range is the showstopper
marimo edit notebook.py --sandbox
Browser support
Tested and works in Chromium-based browsers. Safari mostly works, but had issues with some images not rendering in HDR.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hdrviz-0.2.1.tar.gz.
File metadata
- Download URL: hdrviz-0.2.1.tar.gz
- Upload date:
- Size: 83.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38ec3462f611bb477aa87a6405480a3ae57199ba47ed2a6c1e670adf9944f50c
|
|
| MD5 |
9c003f7b3bb39f749410b65a3608bd80
|
|
| BLAKE2b-256 |
bf4c00b52af87a46a3f1d9b46257b18fd1d86142462060de1684b2dee0ef5566
|
Provenance
The following attestation bundles were made for hdrviz-0.2.1.tar.gz:
Publisher:
publish.yml on ktaletsk/hdrviz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hdrviz-0.2.1.tar.gz -
Subject digest:
38ec3462f611bb477aa87a6405480a3ae57199ba47ed2a6c1e670adf9944f50c - Sigstore transparency entry: 1462975355
- Sigstore integration time:
-
Permalink:
ktaletsk/hdrviz@5b6b5185bdfce6a30cdd64b126a999a9c0722830 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ktaletsk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5b6b5185bdfce6a30cdd64b126a999a9c0722830 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hdrviz-0.2.1-py3-none-any.whl.
File metadata
- Download URL: hdrviz-0.2.1-py3-none-any.whl
- Upload date:
- Size: 48.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
702f9b18d7bb7809b855f99a7fb8a9a2bcfe3905971bbc51acf1f83ca0153c1b
|
|
| MD5 |
1523c8a71edc6f9df1b1b0a0e1649782
|
|
| BLAKE2b-256 |
eb24438fa332666f9319aa7179c7766445ed66711be17b192d70a5c362045aa3
|
Provenance
The following attestation bundles were made for hdrviz-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on ktaletsk/hdrviz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hdrviz-0.2.1-py3-none-any.whl -
Subject digest:
702f9b18d7bb7809b855f99a7fb8a9a2bcfe3905971bbc51acf1f83ca0153c1b - Sigstore transparency entry: 1462975374
- Sigstore integration time:
-
Permalink:
ktaletsk/hdrviz@5b6b5185bdfce6a30cdd64b126a999a9c0722830 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ktaletsk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5b6b5185bdfce6a30cdd64b126a999a9c0722830 -
Trigger Event:
push
-
Statement type: