Skip to main content

Intel Open Image Denoise(OIDN) python binding.

Project description

PyOIDN: Intel Open Image Denoise Python binding

GitHub Tag Tests Docs

Yet another unofficial Intel Open Image Denoise (OIDN) Python binding -- but more Pythonic. Checkout docs for more details.

Features

  • Directly use NumPy arrays as input/output images.
  • Support all OIDN filter types.
  • Simple and clean API design.
  • Lightweight: only depends on NumPy and the OIDN shared library.
  • CUDA device support (via PyTorch).

Install

To install the latest release from PyPI:

pip install pyoidn

The default installation only includes lightweight CPU support with NumPy. Additionally, pyoidn provides support via PyTorch which enables CUDA device support:

pip install pyoidn[torch]

Note: this variant doesn't support Intel Macs, use the default installation instead.

Quickstart

Given a noisy image, plus its normal map and albedo map, denoise and save the result.

noisy_color

import numpy as np
from PIL import Image
import pyoidn


def load_image(path: str) -> np.ndarray:
    return np.array(Image.open(path), dtype=np.float32) / 255.0


color = load_image(color_path)
normal = load_image(normal_path)
albedo = load_image(albedo_path)
result = np.zeros_like(color, dtype=np.float32)

device = pyoidn.Device()
device.commit()

flt = pyoidn.Filter(device, "RT")
flt.set_image(pyoidn.OIDN_IMAGE_COLOR, color, pyoidn.OIDN_FORMAT_FLOAT3)
flt.set_image(pyoidn.OIDN_IMAGE_NORMAL, normal, pyoidn.OIDN_FORMAT_FLOAT3)
flt.set_image(pyoidn.OIDN_IMAGE_ALBEDO, albedo, pyoidn.OIDN_FORMAT_FLOAT3)
flt.set_image(pyoidn.OIDN_IMAGE_OUTPUT, result, pyoidn.OIDN_FORMAT_FLOAT3)

flt.commit()
flt.execute()

# Always check errors if something looks off
assert device.get_error() is None

result_u8 = np.array(np.clip(result * 255, 0, 255), dtype=np.uint8)
Image.fromarray(result_u8).save(output_path)

flt.release()
device.release()

The result:

denoised_result

pyoidn also supports RAII-style resource management using context managers:

with pyoidn.Device() as device:
    device.commit()
    with pyoidn.Filter(device, "RT") as flt:
        flt.set_bool("hdr", True)
        # set images and other parameters
        flt.commit()
        flt.execute()

If you have installed the PyTorch support, you can also use CUDA devices:

torch_device = torch.device("cuda:0")
color_t = torch.from_numpy(color).to(device=torch_device, dtype=torch.float32).contiguous()
normal_t = torch.from_numpy(normal).to(device=torch_device, dtype=torch.float32).contiguous()
albedo_t = torch.from_numpy(albedo).to(device=torch_device, dtype=torch.float32).contiguous()
result_t = torch.zeros_like(color_t, dtype=torch.float32, device=torch_device)
with pyoidn.Device(torch_device) as device:
    device.commit()
    with pyoidn.Filter(device, "RT") as flt:
        # set images and other parameters
        flt.set_image(pyoidn.OIDN_IMAGE_COLOR, color_t, pyoidn.OIDN_FORMAT_FLOAT3)
        flt.set_image(pyoidn.OIDN_IMAGE_NORMAL, normal_t, pyoidn.OIDN_FORMAT_FLOAT3)
        flt.set_image(pyoidn.OIDN_IMAGE_ALBEDO, albedo_t, pyoidn.OIDN_FORMAT_FLOAT3)
        flt.set_image(pyoidn.OIDN_IMAGE_OUTPUT, result_t, pyoidn.OIDN_FORMAT_FLOAT3)

        flt.commit()
        flt.execute()

Notes

  • Error handling: use device.get_error() after creating/committing/executing.
  • Async example: see tests/test.py.

Documentation

Build locally:

pip install -r requirements-docs.txt
mkdocs serve

Roadmap

  • CPU device support
  • NumPy array support
  • All filter types support
  • OIDN buffer support
  • RAII-style resource management
  • More device types
    • CUDA (torch)
    • SYCL
    • Metal
  • Documents
  • Examples

License

This project is licensed under the MIT License. See LICENSE.

This project includes:

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pyoidn-2.5.0.1-py3-none-win_amd64.whl (52.7 MB view details)

Uploaded Python 3Windows x86-64

pyoidn-2.5.0.1-py3-none-manylinux2014_x86_64.whl (83.9 MB view details)

Uploaded Python 3

pyoidn-2.5.0.1-py3-none-macosx_12_0_arm64.whl (48.4 MB view details)

Uploaded Python 3macOS 12.0+ ARM64

pyoidn-2.5.0.1-py3-none-macosx_10_15_x86_64.whl (48.9 MB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file pyoidn-2.5.0.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyoidn-2.5.0.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 52.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for pyoidn-2.5.0.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1616850bb24eb1ca44f9481538eb0a1fd690c91533d23c4614a38a6adf4393f2
MD5 c11c6cef5be7477fcaaa0d0adab0d7ee
BLAKE2b-256 7aab630351a02550f387323297790aaa22a7e71a6f589881aa3fe97be4e1da14

See more details on using hashes here.

File details

Details for the file pyoidn-2.5.0.1-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyoidn-2.5.0.1-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b9a8cc1e954fae9fbbcd8aef70008a5ca837fbe19bd56769f03dd9b2b514756
MD5 cd1ed700a3757593c80531e73ef3afcd
BLAKE2b-256 52cbc731ea910aa01750288428c2412da2672f180374b35f83d50fc151f57416

See more details on using hashes here.

File details

Details for the file pyoidn-2.5.0.1-py3-none-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyoidn-2.5.0.1-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 4580b041212511f81de5728c811fea5438521a59ce741fbf237110cc4d980649
MD5 01d3b80d34f74e268aff5c5c7d595d92
BLAKE2b-256 653f102d5f004b25c0c6259f36b2c38e1ea84a855c6fd8c8cb291e1fadeda464

See more details on using hashes here.

File details

Details for the file pyoidn-2.5.0.1-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyoidn-2.5.0.1-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d7ae9ce478cc678604ffd1ba5615a1b2b60b2b1ec77ae0f9de5ea807b37a3070
MD5 39e02c3f49626e24e106e4a55b405e82
BLAKE2b-256 d266e39c8a29aceee6d404ee15d2fa7002074586d338298f8ebd6dcc83858d2c

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