Skip to main content

Python Version License: MIT tests PyPI - Version GitHub last commit

Oblique Interpolation for Oblique Plane Microscopy

A GPU-accelerated oblique interpolation library for oblique plane microscopy (OPM) volume reconstruction. Avoids aliasing and interpolation artifacts caused by rectilinear interpolation approaches.

Links: API documentation, GitHub repository

Background

Oblique Plane Microscopy (OPM) acquires 3D volumes by scanning an inclined light sheet through the sample. Because the imaging plane is tilted relative to the camera axes, standard rectilinear interpolation during volume reconstruction can introduce aliasing artifacts and loss of resolution – problems that are ameliorated by oversampling, Fourier stitching or deconvolution (see McFadden et al. 2025 and Lamb et al. 2025).

opm_unshear performs true oblique interpolation in the sample’s native coordinate frame, mapping voxels along the tilted plane directly onto an isotropic grid (see Hoffmann et al. 2023, Equation 2). We achieve both artifact-free reconstructions and GPU-accelerated throughput.

Features

  • Oblique interpolation in oblique space, avoiding aliasing from misaligned sampling axes
  • CUDA-accelerated compute kernel for real-time GPU processing (opm_unshear.gpu.unshear, ~1 gigavoxel/s on a NVIDIA RTX 3090)
  • Numba-accelerated multi-threaded CPU fallback for non-GPU systems (opm_unshear.cpu.unshear, ~0.1 gigavoxel/s on a 16-core CPU)

Installation

Hardware Requirements

  • Linux or Windows PC
  • For GPU acceleration (recommended): CUDA-capable NVIDIA GPU with sufficient memory (≥ 10 bytes per voxel of the volumes to be processed) and drivers supporting CUDA version ≥ 11.2 (check with nvidia-smi)

Install opm_unshear

  1. Install dependencies using conda/mamba (recommended, installs CuPy and the CUDA libraries for GPU support):
  • clone or download environment.yml and type conda env create -n opm_unshear_env -f environment.yml (or if you already have a conda environment: conda env update -f environment.yml)
  1. Install opm_unshear:
  • conda activate opm_unshear_env (or the name of your conda environment)
  • pip install "opm_unshear[cli]" (or, for development, clone this repository, change to the directory containing pyproject.toml and run: pip install -e ".[test]")

Without conda, pip install opm_unshear installs the CPU version (NumPy + Numba). For GPU support without conda, use pip install "opm_unshear[gpu]" (installs cupy-cuda12x; do not combine with a conda-installed CuPy). The extra [cli] adds the packages needed by the command line interface (h5py, hdf5plugin, tifffile, scipy).

opm_unshear.unshear uses the GPU implementation if an NVIDIA driver, CuPy and a GPU are found, and the CPU implementation otherwise (opm_unshear.gpu_available tells which). Set the environment variable OPM_UNSHEAR_FORCE_CPU=1 to always use the CPU.

Use

Geometry and parameters

The oblique interpolation function requires the following parameters:

  • data: the input data, a 3D array of shape (p, v, h), where p is the number of oblique planes (camera frames), v is the number of vertical camera pixels, and h is the number of horizontal camera pixels. (note that we are using numpy-standard C-order indexing, where the axes are ordered from slowest-varying to fastest-varying)
  • slope(float): Imagining an ideal pencil parallel to the optical axis, this is the shift of the pencil image, in v camera pixels, between consecutive camera frames. It can be estimated in practice by imaging any structured sample and inspecting the apparent drift between camera frames. This parameter can be positive or negative, depending on the direction of plane scanning or oblique plane tilt. You can also use opm_unshear.get_slope to calculate this value based on setup parameters (angles are measured between the oblique plane and the optical axis). For a sheet at angle θ to the optical axis, a scan step dp and a camera pixel size p (in the sample, along the sheet), slope = dp / (p · sin θ).
  • sub_j(int): subsampling factor along the vertical direction (axis 1, along the optical axis) of the output dataset. Values should be between 1 (no subsampling) and abs(slope).
  • sup_i(float): supersampling factor along the plane-scanning direction (axis 0 of the output). Values should be between 1 and abs(slope) (higher values are possible but this just wastes memory).
  • fill_value(float, optional): value of output voxels that receive no input data (default 0). Note that the output covers the input's plane range at mid-height (axis 1), so two corners of the output volume are always empty.

Example geometry with slope=3, sub_j=2, sup_i=2 (showing a slice along axis 2, or "h"):

               input                                      output
            o-----o-----o                             o--o--o--o--o
             \     \     \                            |  |  |  |  |
              o-----o-----o                           |  |  |  |  |
               \     \     \                          |  |  |  |  |
        axis 1  o-----o-----o       -->       axis 1  o--o--o--o--o
         ("v")   \     \     \                        |  |  |  |  |
                  o-----o-----o                       |  |  |  |  |
                   \     \     \                      |  |  |  |  |
                    o-----o-----o                     o--o--o--o--o
                        axis 0 ("p")                      axis 0

Python API

import numpy as np
from opm_unshear import unshear, get_slope

slope, _, _ = get_slope(n1=1.33, n2=1, M12=1.6, M23=2, dv=5, dp=2, theta_sample=np.radians(30), polarity=1)
#polarity = 1 or -1, depending on the direction of plane scanning

data = np.random.rand(20, 30, 40).astype(np.float32)
result = unshear(data, sub_j=2, sup_i=2, slope=slope)

Command line interface (CLI)

python -m opm_unshear data.h5:dataset_name result.h5 --sub_j 2 --sup_i 2 --slope 5
  • first argument: path to the input file containing a 3D dataset to be deskewed (.npy, .tif/.tiff, .h5/.hdf5, .mat). For hierarchical file formats (.h5 or .mat), specify the dataset name using the format filename.h5:dataset_name. Note that the dataset's axes have to be ordered as described above.
  • second argument (optional): path to the output file (.h5, default: unshear_output.h5). The result is stored in the dataset unsheared_data.
  • --slope (required), --sub_j, --sup_i, --fill_value: as described above
  • --out_dtype: output data type (default: float32; integer types are rounded and clipped)
  • the GPU implementation is used if available, otherwise the CPU implementation

Feedback and contributions

We value your feedback! If you encounter issues, have suggestions for improvements, or simply want to let us know that opm_unshear worked well for you, please reach out:

  • Bug Reports: Open an issue on our GitHub Issues page.
  • Feature Requests: If you have ideas for new features, feel free to suggest them via a GitHub issue.

We welcome contributions! Please:

  • Follow the existing coding style and include tests for new features or fixes.
  • Fork the repo, create a branch, and submit a pull request (PR) with a clear description.

Citing our work

If you use opm_unshear in your research, please cite the paper that first described our interpolation approach:

Hoffmann, M., Henninger, J. et al. Blazed oblique plane microscopy reveals scale-invariant inference of brain-wide population activity. Nature Communications 14, 8019 (2023). https://doi.org/10.1038/s41467-023-43741-x

@article{Hoffmann2023,
  title={Blazed oblique plane microscopy reveals scale-invariant inference of brain-wide population activity},
  author={Hoffmann, Maximilian and Henninger, Jorg and Veith, Johannes and Richter, Lars and Judkewitz, Benjamin},
  journal={Nature Communications},
  volume={14},
  number={1},
  pages={8019},
  year={2023},
  publisher={Nature Publishing Group},
  doi={10.1038/s41467-023-43741-x}
}

See also

Metadata

Release files for opm-unshear 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opm-unshear 0.1.0
File Size Uploaded Provenance Actions
opm_unshear-0.1.0.tar.gz 20.3 kB Without provenance Details for opm_unshear-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for opm-unshear 0.1.0
File Interpreter ABI Platform Actions
opm_unshear-0.1.0-py3-none-any.whl Python 3 none any Details for opm_unshear-0.1.0-py3-none-any.whl

Total release size: 34.8 kB

Release files / opm_unshear-0.1.0.tar.gz

Download URL opm_unshear-0.1.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
847aebac2bea497fe9bfd4cb066790fb1f9957fd2f072b4a36990f8efbf9beaf
BLAKE2b-256 checksum
How to use checksums
ed27eb06ea3a401eeadee356e74ad51c2eb9dcb0d2b144286542d731bc7dd2b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / opm_unshear-0.1.0-py3-none-any.whl

Download URL opm_unshear-0.1.0-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d750a6a215831a89e9ba56e5c262985671bc4b7d755cf92daf21e0b6f3e3606
BLAKE2b-256 checksum
How to use checksums
d22cf9176b831f7caf7a08f79ddb10f761eb4463719bfd4c6be0b3459c5d5377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for opm-unshear 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page