Skip to main content

No project description provided

Project description

Overview

Command line utility and python/rust library to preview a photon cube as a video or a series of frames and/or convert it to a different format.

Features:

  • Zero runtime dependencies, except for FFmpeg, which will be automatically downloaded if not found on path.
  • Multi-threaded and (despite very unoptimized code) blazing fast, usually an order of magnitude or two faster than equivalent cpu-based numpy+numba code.
  • Supports a collection of .bin or .npy file. Assumes bitpacking in the width axis in all cases.
  • Demosaicing, inpainting, tonemapping, inverting SPAD response, and transforms (rotate/flip) are also supported.

Limitations:

  • Not all features are exposed to python yet.

Getting Started

To compile it locally, simply clone the repository, cd into it and run:

pip install -v . 

Ensure you have an up-to-date pip, and an adequate rust toolchain installed (install from here), else this might fail. This should work for python >= 3.8 (tested with 3.8 and py 3.12). You might have to update your rust toolchain with rustup update (MSRV: 1.74.0).

This should pull in any rust dependencies and compile bindings that are compatible with your machine's env. It will create both a CLI and package.
If this is your first time compiling a rust project, this may take a few minutes.

CLI Usage:

Three main functions are available via the CLI: preview, process, and convert.

$ photoncube -h

Convert a photon cube (npy file/directory of bin files) between formats or to a video preview (mp4) by naively averaging frames

Usage: photoncube <COMMAND>

Commands:
  convert  Convert photoncube from a collection of .bin files to a .npy file
  preview  Extract and preview virtual exposures from a photoncube
  process  Apply corrections directly to every bitplane and save results as new .npy file
  help     Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

For more info, run photoncube <COMMAND> --help.

Preview

To preview a photoncube as a video or series of frames (either averaged or single bitplanes), the photon cube needs to be saved as a npy file. See convert for how to convert a folder of .bin files to an .npy file.

Here we preview a photoncube as a video and apply a rotation by 270 degrees then flip frames left-right:

photoncube preview -i binary.npy -t=rot270 -t=flip-lr -o video.mp4

Note: Transforms can be composed arbitrarily, and order matters. Valid transforms are enumerated here and are serialized in kebab-case, i.e: Transform::FlipLR is "flip-lr" and so on.

You can annotate frames and correct for cfa arrays and inpaint like so:

photoncube preview -i binary.npy -a --cfa-path=rgbw_oh_bn_color_ss2_corrected.png --inpaint-path=colorspad_inpaint_mask.npy -o video.mp4

Note: Multiple inpaint-paths can be specified. These masks will be OR'd together then used.

Individual frames can be saved using the --img-dir option, and a range of frames, as well as the window over which we aggregate frames, can be specified:

photoncube preview -i binary.npy --img-dir=frames/ --start=20000 --end=50000 --burst-size=100

Note: You can, of course, save a video and frames at the same time!

In particular, if you wish to view individual bitplanes, you can set burst-size to one, and use the step argument to skip over frames as to not create a huge video. For a photoncube captured at 15kHz, a realtime playback of individual bitplanes can be shown:

photoncube preview -i binary.npy --batch-size=1 --step=625 -o video.mp4

Note: Here we set step=625 because the default playback speed is 24 fps (i.e: 15k/24 == 625), but the fps can also be changed using --fps, although using a very large or small fps will cause ffmpeg issues.

Process

Many of the operations detailed above can be applied directly to a photoncube at the bitplane level, notably all transforms, slicing operations (start/end) and inpainting/cfa-correction can be applied. The later will use a dithering-like approach to perform stochastic inpainting. Again, only numpy files are supported.

Here we process a photoncube by applying cfa corrections and a few transforms:

photoncube process -i binary.npy --cfa-path=rgbw_oh_bn_color_ss2_corrected.png --inpaint-path=colorspad_inpaint_mask.npy --start=0 --end=100000 -t flip-lr -o processed.npy

Convert

You can convert from a collection of .bin files to a single .npy file like so:

photoncube convert -i <DIR OF BINS> -o <OUTPUT>

By default this assumes half array frames (i.e: 256x512), you can specify --full-array for the whole array.

Library Usage (Python)

The python API mirrors the rust and CLI functionality, for more info on how to use it please see the above section.

from photoncube import PhotonCube, Transform

PhotonCube.convert_to_npy(
    # Directory containing `.bin` files
    "full-array/binary/16kHz/", 
    "test.npy", 
    is_full_array=True, 
    message="Converting..."
)

# Open cube 
pc = PhotonCube.open("test.npy")

# Get a frame
frame = pc[10]

# Load inpainting masks, both .png and .npy supported.
pc.load_mask("dead_pixels.png")
pc.load_mask("hot_pixels.npy")

# Inpainting masks will be OR'ed together
print(pc.inpaint_mask)

# If using colorspad, you can specify the color filter array 
# and all non-white pixels will be interpolated out
pc.load_cfa("cfa.png")

# Generate 100 preview images with bit-depth of 256 
pc.set_range(0, 25600, 256)
pc.save_images(
    "tmp/", 
    invert_response=False,
    tonemap2srgb=False,
    colorspad_fix=False,
    grayspad_fix=False,
    annotate_frames=False,
    message="Saving Images..."  # If not None, a progress bar will be drawn
)

# Make video preview instead, but transform frames first, and invert the SPAD
# response, and normalize to a 95% quantile, for better low-light performance
pc.set_transforms([Transform.Rot90, Transform.FlipUD])
pc.set_quantile(0.95)
pc.save_video(
    "output.mp4", fps=24, 
    # If specified, images are also saved
    img_dir=None,
    invert_response=True,
    # Options from `save_images` can be used here too:
    message="Making video..." 
) 

# Save a new photoncube that has been processed with any transforms,
# cfas, masks or color/grayspad fixes  such as cropping dead regions or column swapping.
pc.process_cube("processed.npy")

For the full python API and up-to-date typing, see photoncube.pyi.

Development

We use maturin as a build system, which enables this package to be built as a python extension using pyo3 bindings. Some other tools are needed for development work, which can be installed using pip install -v .[dev].

There are both rust tests, and python ones, run them with:

cargo test && pytest . 

Code Quality

We use rustfmt to format the codebase, we use some customizations (i.e for import sorting) which require nightly. First ensure you have the nightly toolchain installed with:

rustup toolchain install nightly

Then you can format the code using:

cargo +nightly fmt 

Similarly we use black to format the python parts of the project.

To keep the project lean, it's recommended to check for unused dependencies using this tool, or this one, like so:

cargo +nightly udeps
cargo machete --with-metadata

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

photoncube-0.3.14.tar.gz (447.9 kB view details)

Uploaded Source

Built Distributions

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

photoncube-0.3.14-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

photoncube-0.3.14-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

photoncube-0.3.14-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file photoncube-0.3.14.tar.gz.

File metadata

  • Download URL: photoncube-0.3.14.tar.gz
  • Upload date:
  • Size: 447.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.0

File hashes

Hashes for photoncube-0.3.14.tar.gz
Algorithm Hash digest
SHA256 d46ada6af3f330df8060854150e011c8f8a4b36c9f2b3792ee02175a605a4c36
MD5 09e9907c1c5837235894000f363ad4fa
BLAKE2b-256 fbe2ca538ea17f0a749a27439fed4809448d6882a3a1353b7a66ecf0acbfbb9d

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3001b9efab9595087bedb7376c95470218827524bdf1aeb1f8efab91ebda4e4
MD5 20280fa117aebc6ca596e977f184e8b1
BLAKE2b-256 5889570a430e626d5f58ca880054a1b25b4227fb4a6b8cbba253342025896a4e

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 135ec627a9d35c56df13ab2161a133b1a06e69fa3409c9f80940b914c771ddb7
MD5 9a20221021f971ea1a7acaa10ed83b6e
BLAKE2b-256 832c203e878204cc1e8d015a87f42e633165ed15181356eb97581fdec8f163fe

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3962cbc2898019879fb126b235ce6b6741ee4b86576fa7c8c353b6ff8d656cf6
MD5 653f54d51a202dd94de5a35581f7d746
BLAKE2b-256 a8ea7b571b9e86138a8c0baeeae8a87da617f871c37cbe17d5c7506938e3e4ab

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 043f6ecd62eef38b1efd98e7dd1c5c08ea32517a2a5e355b549b294c96f28e89
MD5 fa377cb92d3dd36ab70b2a42339a07d0
BLAKE2b-256 3d4365ca27c9644ab1edd3f27ca440ae7b5a94b06fa61a08caa9b26e66f8e9a3

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 938b906d617324927e04e155748460678d55fe938166eea86bfa6b1be628dd74
MD5 0ca008f96958f0969b508676f346cdaa
BLAKE2b-256 4f9624bbba8b7fce445786ae163a1dd9e6498dd50191ee4b6191099aec3268ca

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 770be9d824a4e32acafb915377120c551de56f1a4c7c46750e4641f9ec8997f1
MD5 6e7bca07590631d81c8a659e7390186a
BLAKE2b-256 41e2c1d13ea0c766cb576c9db7fedc9af3d89465733807a897c15418f10c3512

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a7fc0626df6681e73a844f53c73c6fbeedc71a0e58eefa8a580a5f07844e022
MD5 922a4fed67e86d6a4eea84eca57bcabc
BLAKE2b-256 a22f6ddaf5e94c1a52403bd93e8172883410613f0c38fd2846ebb4dde4511739

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58862ae67e858020f9d8f2589d3409c6e396a646ac1592b94125be82d3b66e74
MD5 0528dfaa646611f561b8725ee71f1d34
BLAKE2b-256 f3ec7f1523bac5416b93620c43b5bdb830c2d8f621fe0ae53dfc3f1b7926188e

See more details on using hashes here.

File details

Details for the file photoncube-0.3.14-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for photoncube-0.3.14-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6841c7dff20f38c816197b9b64f7744fd99427ed922c6ead55e0bc5bb2c6aae9
MD5 49e0167c4360f44f54a2f2e0ab8bb622
BLAKE2b-256 5da4401c3c0a5dd1da30613188681cbfa374034d5ef13abc615e39d6c2f984f4

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