Skip to main content

Bijective metric-depth <-> RGB colormap along a 3D Hilbert cube walk, as used in the Vision Banana paper.

Project description

🎨 3D Hilbert Depth Colormap

Give your depth estimation a fancy new colormap! Here you'll find an implementation of a bijective metric-depth <-> RGB mapping along a 3D Hilbert cube walk, as used in the Vision Banana 🍌 paper [1].

📦 Installation

From PyPI:

pip install hilbertmap

From source:

git clone https://github.com/massimilianoviola/hilbertmap
cd hilbertmap
pip install -e .

🛠️ Usage

Direct encoding/decoding

import numpy as np
from hilbertmap import depth_to_rgb, rgb_to_depth

depth = np.load("depth.npy")          # (H, W) float meters
rgb   = depth_to_rgb(depth)           # (H, W, 3) float in [0, 1]
back  = rgb_to_depth(rgb)             # (H, W) recovered meters

Visualization with matplotlib

import matplotlib.pyplot as plt
import hilbertmap as hm

im = plt.imshow(depth, cmap=hm.cmap(), norm=hm.Norm())
hm.colorbar(im, label="depth (m)")
plt.show()

hm.Norm applies the fixed power transform; hm.colorbar paints only the cmap subset the data actually covers.

🧭 How it works

The seven-edge Hamiltonian path on the RGB cube (left) carries depth values from black at zero to white at infinity. The shape parameters $\lambda$ and $c$ produce different saturation curves (right) that decide how much depth lives on each segment of the walk.

Cube walk Saturation curves
cube walk saturation curves

Unbounded metric depth $d \in [0, \infty)$ is squashed into $[0, 1)$ by a power transform from Barron (2025) [2]:

$$f(d, \lambda, c) = 1 - \left(1 - \frac{d}{\lambda c}\right)^{\lambda + 1}$$

With defaults $\lambda = -3$, $c = 10/3$ this simplifies to $f(d) = 1 - (1 + d/10)^{-2}$, mapping $d \in [0, \infty)$ to $f \in [0, 1)$, which is then read as the fractional position along the edge walk to land on $\mathrm{RGB} \in [0, 1]^3$. The mapping is a strict bijection, so any RGB encoding can be decoded back to metric depth by projecting onto the nearest edge.

Because the utility of accurate metric depth for nearby image content is generally higher than that of distant content, the default parameters $\lambda = -3$, $c = 10/3$ make the cube walk most sensitive in the first few meters and saturate beyond ~35 m. This behavior can be tuned by changing the parameters to get more meaningful color variation on deep outdoor scenes.

📚 References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hilbertmap-0.1.0.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hilbertmap-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file hilbertmap-0.1.0.tar.gz.

File metadata

  • Download URL: hilbertmap-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hilbertmap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 288b0e5864ce9a67153b6910166142a3ee18a8226173eaa840fc3435e3e10ebf
MD5 400ba264c6803101bf3f781d546ff05b
BLAKE2b-256 1779ae8f0bd0bbd9305e4ca0e7bff1f149109bb04870864d967357c579322803

See more details on using hashes here.

File details

Details for the file hilbertmap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hilbertmap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hilbertmap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba6f288832c5c0a9f82daa889deca12df7cf1142318722a4fe6173f70b5a718a
MD5 e8c84e05127a4ac6f6d1feb8c124d9f4
BLAKE2b-256 16bee7d11f9183750be8b0a62fdeeabed0ea0344cdaea86292ccfd43dfae935d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page