Convert depth map images to normal map images
Project description
depth2normal
Convert depth map images to RGB normal maps for shading and 3D workflows.
Requirements: Python 3.10 or newer. Runtime dependencies are NumPy, SciPy, Pillow, and Click (no OpenCV).
| Depth (input) | Normal map (output) |
|---|---|
Install
From PyPI (after you publish the package):
pip install depth2normal
With uv in another project (not this repository):
uv add depth2normal
Or without editing that project’s pyproject.toml:
uv pip install depth2normal
Note: Inside this repository, do not run
uv add depth2normal—the project name matches the package name, and uv blocks that self-dependency. Useuv syncinstead (see below).
Usage
All CLI forms share the same options (see table at the end of this section).
After pip install or uv pip install
depth2normal path/to/depth.png -o normal.png
From a clone (recommended for development)
Install the project and dev tools, then use the console script or the helper script:
git clone https://github.com/cobanov/depth2normal.git
cd depth2normal
uv sync
uv run depth2normal assets/depth.png -o normal.png
Or run the repo-root helper without an editable install (still uses deps from uv sync):
uv run run.py assets/depth.png -o normal.png
With plain python (dependencies must be available in that environment, e.g. after pip install -e .):
python run.py assets/depth.png -o normal.png
Module entry point when src is on PYTHONPATH or the package is installed:
PYTHONPATH=src python -m depth2normal assets/depth.png -o normal.png
Python API
import depth2normal
depth2normal.convert("depth.png", "normal.png")
depth2normal.convert("depth.png", "normal.png", strength=2.0, method="gaussian", sigma=1.5)
import numpy as np
depth_array = np.load("depth.npy")
normal_map = depth2normal.depth_to_normal(depth_array, method="scharr")
CLI options
| Option | Default | Description |
|---|---|---|
-o, --output |
normal_map.png |
Output image path |
-s, --strength |
1.0 |
Scales gradients (stronger = more pronounced normals) |
-m, --method |
gaussian |
Gradient algorithm: gaussian, sobel, or scharr |
--sigma |
1.0 |
Gaussian kernel width (only with --method gaussian) |
--version |
— | Print version and exit |
Positional argument: path to the depth image file.
Gradient methods
| Method | Quality | Speed | Notes |
|---|---|---|---|
gaussian |
Best | Moderate | Smooth normals via Gaussian derivative. --sigma controls the smoothness/detail tradeoff. |
sobel |
Good | Fast | Classic 3x3 Sobel. Sharp but can show staircase artifacts on quantized depth. |
scharr |
Good | Fast | Better rotational accuracy than Sobel, similar speed. |
How it works
- Load depth as grayscale float array.
- Estimate surface gradients with the selected filter (Gaussian derivative, Sobel, or Scharr).
- Build normals (-dx, -dy, 1), normalize to unit length, then map to 8-bit RGB.
Development
uv sync
uv run pytest
uv run ruff check .
uv run ruff format --check .
License
MIT
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 depth2normal-1.0.0.tar.gz.
File metadata
- Download URL: depth2normal-1.0.0.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3aa7f5a08e47e5904d298b03cbd387f63ce26cecdb6ada7d28345b304ff10e0
|
|
| MD5 |
2d978a7cf3b5b159b82a21846fac4761
|
|
| BLAKE2b-256 |
4613ff13c581bbbc98df35b9eb7819e85bd4109bbf4224bf3359eb437e9ebe74
|
Provenance
The following attestation bundles were made for depth2normal-1.0.0.tar.gz:
Publisher:
release.yml on cobanov/depth2normal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
depth2normal-1.0.0.tar.gz -
Subject digest:
e3aa7f5a08e47e5904d298b03cbd387f63ce26cecdb6ada7d28345b304ff10e0 - Sigstore transparency entry: 1242687878
- Sigstore integration time:
-
Permalink:
cobanov/depth2normal@3e15f69ff5da15da764d14400eeb257544979a4d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cobanov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3e15f69ff5da15da764d14400eeb257544979a4d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file depth2normal-1.0.0-py3-none-any.whl.
File metadata
- Download URL: depth2normal-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b051e4dd2285ff93a653554649addde947bb14ec1b0dd89c81c9995ed79db75
|
|
| MD5 |
2c8f9050d7a8b8233db11458bba1d746
|
|
| BLAKE2b-256 |
7e40decb15254330ce9dab06f7fbe9f8d7b5961b77fbacdb8d0b17230b088b02
|
Provenance
The following attestation bundles were made for depth2normal-1.0.0-py3-none-any.whl:
Publisher:
release.yml on cobanov/depth2normal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
depth2normal-1.0.0-py3-none-any.whl -
Subject digest:
7b051e4dd2285ff93a653554649addde947bb14ec1b0dd89c81c9995ed79db75 - Sigstore transparency entry: 1242687885
- Sigstore integration time:
-
Permalink:
cobanov/depth2normal@3e15f69ff5da15da764d14400eeb257544979a4d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cobanov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3e15f69ff5da15da764d14400eeb257544979a4d -
Trigger Event:
workflow_dispatch
-
Statement type: