Torch implementation of the NoRMCorre motion correction algorithm.
Project description
PyCorre
Fast, GPU-accelerated rigid and piecewise-rigid motion correction for calcium-imaging recordings. PyCorre implements the NoRMCorre algorithm, which is the same phase-correlation + upsampled-DFT method used by CaImAn, but rewritten in PyTorch. The whole stack is corrected in batched operations that run on CPU or GPU from a single, dependency-light codebase.
Installation
pip install pycorre
The only runtime dependencies are torch, numpy, and tqdm. GPU support is
whatever your PyTorch build provides (install the appropriate CUDA wheel of
torch for your machine).
Quickstart
import numpy as np
from pycorre import RigidMotionCorrection, PWRigidMotionCorrection
# A recording of shape (n_frames, height, width); numpy array or torch tensor.
frames = ...
# Rigid correction on the GPU.
model = RigidMotionCorrection(device="cuda") # or "cpu" / "auto"
corrected = model.fit_transform(frames)
# Piecewise-rigid (non-rigid) correction.
model = PWRigidMotionCorrection(device="cuda", strides=(96, 96), overlaps=(32, 32))
corrected = model.fit_transform(frames)
The API follows scikit-learn's fit / transform / fit_transform pattern.
fit estimates the template (unless you pass one) and finds the per-frame
shifts; transform applies them. Inputs may be numpy arrays or torch tensors;
numpy in and numpy out.
Performance
The table below shows the rigid correction throughput on a real recording with resolution 360x640 for 1800 frames.
| method | device | fps | vs PyCorre (GPU) |
|---|---|---|---|
| PyCorre (torch) | GPU | ~2,285 | 1.0x |
| jnormcorre (NoRMCorre in JAX) | GPU | ~762 | 3.0x slower |
| PyCorre (torch) | CPU | ~468 | 4.9x slower |
| jnormcorre | CPU | ~162 | 14x slower |
| CaImAn reference | CPU | ~103 | 22x slower |
On this sample, PyCorre is ~22x faster than CaImAn and ~3x faster than jnormcorre. On CPU alone, with no GPU at all, PyCorre still leads, running ~4.5x faster than the CaImAn reference and ~2.9x faster than jnormcorre.
The scaling curve can be seen here:
Author
PyCorre is written and maintained by Ryan 'RyanIRL' Peters (@ryanirl).
Citation
If you use PyCorre in your research, please cite it:
@software{peters_pycorre,
author = {Peters, Ryan},
title = {{PyCorre}: GPU-accelerated rigid and piecewise-rigid motion correction for calcium imaging},
url = {https://github.com/ryanirl/pycorre},
year = {2026}
}
PyCorre implements the NoRMCorre algorithm; if you use it, please also cite the original method:
Pnevmatikakis, E. A., & Giovannucci, A. (2017). NoRMCorre: An online algorithm for piecewise rigid motion correction of calcium imaging data. Journal of Neuroscience Methods, 291, 83-94. https://doi.org/10.1016/j.jneumeth.2017.07.031
License
pycorre is released under the MIT License (see LICENSE).
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 pycorre-0.1.0.tar.gz.
File metadata
- Download URL: pycorre-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18816cd67e5eeb13ed2ad01cab78a60840f43c9c11a99ec29c83e76e2071ea9d
|
|
| MD5 |
f2d08a8cc63d0e721bd68a540b69c7ab
|
|
| BLAKE2b-256 |
bef2f1fc5f61d1f2ea0a94b8a8fe1382e59439d40ed126b22371f6c244a94bd1
|
File details
Details for the file pycorre-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pycorre-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b68e44a9ac8171b0d5054bf7a6492907499105ea44ab93d18aec0a0b91aaa863
|
|
| MD5 |
404bd70d78671895cbca7ef88a179a97
|
|
| BLAKE2b-256 |
5992b9c77ea7ad63ec88ae7c7f9a28d71ccf525dbce831ffecbf5cd8b1c5f8c7
|