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.4.0.2-py3-none-win_amd64.whl (53.6 MB view details)

Uploaded Python 3Windows x86-64

pyoidn-2.4.0.2-py3-none-manylinux2014_x86_64.whl (80.6 MB view details)

Uploaded Python 3

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

Uploaded Python 3macOS 12.0+ ARM64

pyoidn-2.4.0.2-py3-none-macosx_10_15_x86_64.whl (48.8 MB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyoidn-2.4.0.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8e1200c0c44c4027fe737b197f0e9edcc1c34ac9829a549d93957021f2c604f4
MD5 c5ac307308622331df3425963099b90d
BLAKE2b-256 c9255529cafeee8545a1b151a8ee4646f7e024c66717138c2e15cdd08da7ffb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoidn-2.4.0.2-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7e1248e5273da235ecf38eef52c25fc3983ce3c786360a154b54eebd94d001c
MD5 4f5c60987e125a033c891f3699aca054
BLAKE2b-256 c958fd836f5519322456c0afec0b72958074d839a8195a15103e4d9c2bc5060e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoidn-2.4.0.2-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 363a0592376945128ab472cb5128795f4bdcc1bf42fd5c1dc1bb7e79d7c7b0d3
MD5 d82da0a49fe31d4e52ac09c5589319f6
BLAKE2b-256 bc8e670fcbaa393116d981860f52bfc53ef4a2dd48b9dd85ecaaeb79c20ed0c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoidn-2.4.0.2-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ede32fc70b8ef8345ba2ccb12e5e54b8df5c87ebdcbbfb17a8e2c90da117ba99
MD5 f7b89847a342c7bc7af0198963f4f16f
BLAKE2b-256 864e995cce37a7c00bdabf9c5f9d4119014ca57e5d8db85dd7362df8170ef1bd

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