Skip to main content

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)
Depth example Normal map example

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. Use uv sync instead (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

  1. Load depth as grayscale float array.
  2. Estimate surface gradients with the selected filter (Gaussian derivative, Sobel, or Scharr).
  3. 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


Download files

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

Source Distribution

depth2normal-1.0.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

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

depth2normal-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

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

Hashes for depth2normal-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e3aa7f5a08e47e5904d298b03cbd387f63ce26cecdb6ada7d28345b304ff10e0
MD5 2d978a7cf3b5b159b82a21846fac4761
BLAKE2b-256 4613ff13c581bbbc98df35b9eb7819e85bd4109bbf4224bf3359eb437e9ebe74

See more details on using hashes here.

Provenance

The following attestation bundles were made for depth2normal-1.0.0.tar.gz:

Publisher: release.yml on cobanov/depth2normal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for depth2normal-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b051e4dd2285ff93a653554649addde947bb14ec1b0dd89c81c9995ed79db75
MD5 2c8f9050d7a8b8233db11458bba1d746
BLAKE2b-256 7e40decb15254330ce9dab06f7fbe9f8d7b5961b77fbacdb8d0b17230b088b02

See more details on using hashes here.

Provenance

The following attestation bundles were made for depth2normal-1.0.0-py3-none-any.whl:

Publisher: release.yml on cobanov/depth2normal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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