opm_unshear for Python
Project description
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)
Install opm_unshear
- Install CUDA Toolkit
- Using conda/mamba (recommended):
conda create -n opm_unshear_env -f environment.yml(or if you already have a conda environment:conda env update -f environment.yml) - Using NVIDIA's installer (not recommended)
- Install opm_unshear:
conda activate opm_unshear_env(or the name of your conda environment)pip install opm_unshear(or, for development, clone this repository, change to the directory containingpyproject.tomland run:pip install -e .)
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.slope(float): Imagining an ideal pencil parallel to the optical axis, this is the shift of the pencil image, invcamera pixels, between consecutive camera frames. This parameter can be positive or negative, depending on the direction of plane scanning or oblique plane tilt. You can also useopm_unshear.get_slopeto calculate this value.sub_j(int): subsampling factor along the vertical direction of the output dataset (along the optical axis). Values should be between 1 (no subsampling) andabs(slope). Larger values reducethe memory footprint of the output dataset (and are often justified in OPM, depending on axial resolution).sup_i(float): supersampling factor along the plane-scanning direction. Values should be between 1 andabs(slope)(higher values are possible but this just wastes memory). Optimal values depend on the plane spacing, optical resolution and desired memory footprint.
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 --input data.tif --output result.h5 --sub_j 2 --sup_i 2 --slope 5
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opm_unshear-0.0.1.tar.gz.
File metadata
- Download URL: opm_unshear-0.0.1.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a36997e6eca67f631cc17a0425826a40fa33c2f8abdbe1afb4a17912cb5a7349
|
|
| MD5 |
5a7ac53973f7d7f38d830b7db5e4bf4b
|
|
| BLAKE2b-256 |
6a8ccba2739f44cf0a5fe5727b120320ce6f66be2d84c867d3539f7dd6a70607
|
File details
Details for the file opm_unshear-0.0.1-py3-none-any.whl.
File metadata
- Download URL: opm_unshear-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbc644fbfc56f7e59f72306da9102a917374105f4d824d309bc63422a3389f21
|
|
| MD5 |
75f996b8f7a12ca9a615a3228da90504
|
|
| BLAKE2b-256 |
32e40600cca648426ffae537667b649dcc106d5662116d7b72e7c8888e647587
|