Skip to main content

Extract Cryptomatte data from EXR image files

Project description

Decryptomatte

This package works with Cryptomatte images, extracting and manipulating individual layers and their coverage information. It incorporates elements from the original cryptomatte_arnold unit tests, licensed under BSD-3 https://github.com/Psyop/CryptomatteArnold.

Example Artwork by dj3dim

Installation

Install via pip

While you can install this package from PyPi via pip pip install decryptomatte You'll most likely miss the required binary OpenImageIO wheel for your platform.

Install in virtual environment

On Windows, you can however clone this repository and install a binary OpenImageIO wheel from my private package index:

  1. Get Python version > 3.9, tested with 3.11
  2. git clone https://github.com/tappi287/decryptomatte.git
  3. Install poetry
  4. Navigate to the repository directory cd decryptomatte
  5. Run poetry install

You should now be able to import and use this package inside your poetry/virtual environment.

Example

The package contains a convenience script to extract all masks to individual image files. Usage is show below.

from pathlib import Path

from decryptomatte import cryptomatte_to_images

if __name__ == '__main__':
    input_dir = Path('test/data/input')
    output_dir = input_dir / 'out'
    
    sample_matte_img = input_dir / 'BlenderExample.exr'
    sample_beauty_img = input_dir / 'BlenderExample.exr'

    cryptomatte_to_images(sample_matte_img, sample_beauty_img, output_dir=output_dir)

Usage

  1. Importing the Class:
from decryptomatte import Decrypt
  1. Creating an Instance:
  • Basic Instance:
my_object = Decrypt("path/to/your/cryptomatte_image.exr")
  • Instance with Arguments:
my_object = Decrypt("path/to/your/cryptomatte_image.exr", alpha_over_compositing=True)
  • alpha_over_compositing (optional, default False) specifies handling alpha over compositing during certain operations.

Accessing Attributes:

While the class defines internal attributes, use the provided methods to interact with the object.

Methods:

  • list_layers(): Returns available Cryptomatte layer names (IDs).
  • crypto_metadata(): Returns extracted Cryptomatte metadata.
  • sorted_crypto_metadata(): Returns sorted Cryptomatte metadata with ID coverage information.
  • get_cryptomatte_channels(): Returns a NumPy array containing all Cryptomatte image channels.
  • get_mattes_by_names(layer_names: List[str]) -> dict: Retrieves coverage mattes for specified layer names (IDs).
  • _get_mattes_by_ids(target_ids: List[float]) -> Dict[float, np.ndarray]: (internal) Gets individual alpha coverage mattes for IDs.
  • get_masks_for_ids(target_ids: List[float]) -> Generator[Tuple[float, np.ndarray], None, None]: (internal) Generates individual masks (anti-aliased) for each object ID.
  • get_mask_for_id(float_id: float, channels_arr: np.ndarray, level: int = 6, as_8bit=False) -> np.ndarray: (internal) Extracts the mask for a specific ID from Cryptomatte layers.
  • _iterate_image(width: int, height: int, target_ids: list) -> Dict[float, np.ndarray]: (internal) Iterates through all image pixels, collecting coverage values for specified IDs.
  • id_to_name(self, id_float: float) -> str: Returns the human-readable layer name for the provided ID.
  • create_layer_object_name(self, id_float: float) -> str: Creates a human-readable name combining the layer, ID, and object name.
  • get_id_from_readable_layer_name(self, readable_layer_name: str) -> Optional[float]: Attempts to extract the ID from a human-readable layer name.
  • merge_matte_and_id_color(self, matte: np.ndarray, id_float: Optional[float] = None, layer_name: Optional[str] = None) -> np.ndarray: Creates an RGBA image by combining the provided matte with its corresponding ID color.
  • merge_matte_and_rgb(matte: np.ndarray, rgb_img: np.ndarray = None) -> np.ndarray: (static) Merges a matte with an optional RGB image, creating an RGBA image.
  • shutdown(): Releases OpenImageIO resources

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

decryptomatte-1.0.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

decryptomatte-1.0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file decryptomatte-1.0.1.tar.gz.

File metadata

  • Download URL: decryptomatte-1.0.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Windows/10

File hashes

Hashes for decryptomatte-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ff749874c130147f1fb14bc099abfc253fd0c3acbb80c6db1bebaf8dc15df71c
MD5 fc152970a15769293f6481c0e4c08e85
BLAKE2b-256 6d8c96209c20dd90b211ae363134a42b53ec547ff1afd9cd16716856fc7cc0ba

See more details on using hashes here.

File details

Details for the file decryptomatte-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: decryptomatte-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Windows/10

File hashes

Hashes for decryptomatte-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1808195f8fcf913034fb38f5672b58468df492cefb3c3ff99f94be7183eea76c
MD5 d99a3354bbb0f6b4f7144434cb0bc548
BLAKE2b-256 fff19ed89e09d299867f62dc9fa370e9c7efef81771af3a28a643daee697aee8

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