Skip to main content

pyStackReg

Build status Documentation Status PyPI Package latest release Supported Python Versions Downloads

Summary

Python/C++ port of the ImageJ extension TurboReg/StackReg written by Philippe Thevenaz/EPFL.

A python extension for the automatic alignment of a source image or a stack (movie) to a target image/reference frame.

Description

pyStackReg is used to align (register) one or more images to a common reference image, as is required usually in time-resolved fluorescence or wide-field microscopy. It is directly ported from the source code of the ImageJ plugin TurboReg and provides additionally the functionality of the ImageJ plugin StackReg, both of which were written by Philippe Thevenaz/EPFL (available at http://bigwww.epfl.ch/thevenaz/turboreg/).

pyStackReg provides the following five types of distortion:

  • translation

  • rigid body (translation + rotation)

  • scaled rotation (translation + rotation + scaling)

  • affine (translation + rotation + scaling + shearing)

  • bilinear (non-linear transformation; does not preserve straight lines)

pyStackReg supports the full functionality of StackReg plus some additional options, e.g., using different reference images and having access to the actual transformation matrices (please see the examples below).

Please note: The bilinear transformation cannot be propagated, as a combination of bilinear transformations does not generally result in a bilinear transformation. Therefore, stack registration/transform functions won’t work with bilinear transformation when using “previous” image as reference image. You can either use another reference (“first” or “mean” for first or mean image, respectively), or try to register/transform each image of the stack separately to its respective previous image (and use the already transformed previous image as reference for the next image).

Installation

The package is available on conda forge and on PyPi.

  • Install using conda

conda install pystackreg -c conda-forge
  • Install using pip

pip install pystackreg

Documentation

The documentation can be found on readthedocs:

https://pystackreg.readthedocs.io/

Tutorial

Usage

The following example opens two different files and registers them using all different possible transformations

from pystackreg import StackReg
from skimage import io

#load reference and "moved" image
ref = io.imread('some_original_image.tif')
mov = io.imread('some_changed_image.tif')

#Translational transformation
sr = StackReg(StackReg.TRANSLATION)
out_tra = sr.register_transform(ref, mov)

#Rigid Body transformation
sr = StackReg(StackReg.RIGID_BODY)
out_rot = sr.register_transform(ref, mov)

#Scaled Rotation transformation
sr = StackReg(StackReg.SCALED_ROTATION)
out_sca = sr.register_transform(ref, mov)

#Affine transformation
sr = StackReg(StackReg.AFFINE)
out_aff = sr.register_transform(ref, mov)

#Bilinear transformation
sr = StackReg(StackReg.BILINEAR)
out_bil = sr.register_transform(ref, mov)

The next example shows how to separate registration from transformation (e.g., to register in one color channel and then use that information to transform another color channel):

from pystackreg import StackReg
from skimage import io

img0 = io.imread('some_multiframe_image.tif')
img1 = io.imread('another_multiframe_image.tif')
# img0.shape: frames x width x height (3D)

sr = StackReg(StackReg.RIGID_BODY)

# register 2nd image to 1st
sr.register(img0[0, :, :], img0[1,:,:])

# use the transformation from the above registration to register another frame
out = sr.transform(img1[1,:,:])

The next examples shows how to register and transform a whole stack:

from pystackreg import StackReg
from skimage import io

img0 = io.imread('some_multiframe_image.tif') # 3 dimensions : frames x width x height

sr = StackReg(StackReg.RIGID_BODY)

# register each frame to the previous (already registered) one
# this is what the original StackReg ImageJ plugin uses
out_previous = sr.register_transform_stack(img0, reference='previous')

# register to first image
out_first = sr.register_transform_stack(img0, reference='first')

# register to mean image
out_mean = sr.register_transform_stack(img0, reference='mean')

# register to mean of first 10 images
out_first10 = sr.register_transform_stack(img0, reference='first', n_frames=10)

# calculate a moving average of 10 images, then register the moving average to the mean of
# the first 10 images and transform the original image (not the moving average)
out_moving10 = sr.register_transform_stack(img0, reference='first', n_frames=10, moving_average = 10)

The next example shows how to separate registration from transformation for a stack (e.g., to register in one color channel and then use that information to transform another color channel):

from pystackreg import StackReg
from skimage import io

img0 = io.imread('some_multiframe_image.tif') # 3 dimensions : frames x width x height
img1 = io.imread('another_multiframe_image.tif') # same shape as img0

# both stacks must have the same shape
assert img0.shape == img1.shape

sr = StackReg(StackReg.RIGID_BODY)

# register each frame to the previous (already registered) one
# this is what the original StackReg ImageJ plugin uses
tmats = sr.register_stack(img0, reference='previous')
out = sr.transform_stack(img1)

# tmats contains the transformation matrices -> they can be saved
# and loaded at another time
import numpy as np
np.save('transformation_matrices.npy', tmats)

tmats_loaded = np.load('transformation_matrices.npy')

# make sure you use the correct transformation here!
sr = StackReg(StackReg.RIGID_BODY)

# transform stack using the tmats loaded from file
sr.transform_stack(img1, tmats=tmats_loaded)

# with the transformation matrices at hand you can also
# use the transformation algorithms from other packages:
from skimage import transform as tf

out = np.zeros(img0.shape).astype(np.float)

for i in range(tmats.shape[0]):
    tform = tf.AffineTransform(matrix=tmats[i, :, :])
    out[i, :, :] = tf.warp(img1[i, :, :], tform)

Author information

This is a port of the original Java code by Philippe Thevenaz to C++ with a Python wrapper around it. All credit goes to the original author:

/*====================================================================
| Philippe Thevenaz
| EPFL/STI/IMT/LIB/BM.4.137
| Station 17
| CH-1015 Lausanne VD
| Switzerland
|
| phone (CET): +41(21)693.51.61
| fax: +41(21)693.37.01
| RFC-822: philippe.thevenaz@epfl.ch
| X-400: /C=ch/A=400net/P=switch/O=epfl/S=thevenaz/G=philippe/
| URL: http://bigwww.epfl.ch/
\===================================================================*/

/*====================================================================
| This work is based on the following paper:
|
| P. Thevenaz, U.E. Ruttimann, M. Unser
| A Pyramid Approach to Subpixel Registration Based on Intensity
| IEEE Transactions on Image Processing
| vol. 7, no. 1, pp. 27-41, January 1998.
|
| This paper is available on-line at
| http://bigwww.epfl.ch/publications/thevenaz9801.html
|
| Other relevant on-line publications are available at
| http://bigwww.epfl.ch/publications/
\===================================================================*/

License

You are free to use this software for commercial and non-commercial
purposes. However, we expect you to include a citation or acknowledgement
whenever you present or publish research results that are based
on this software. You are free to modify this software or derive
works from it, but you are only allowed to distribute it under the
same terms as this license specifies. Additionally, you must include
a reference to the research paper above in all software and works
derived from this software.

Changelog

0.2.5

fixed

  • Compilation in environment without numpy

0.2.3

added

  • Added example data and tutorial notebook

  • Added unit tests

  • Additional documentation

  • Detection of time series axis in stacks - will raise a warning if supplied axis in stack registration does not correspond to the detected axis

changed

  • progress_callback function now gets called with the iteration number, not iteration index (iteration number = iteration index + 1)

fixed

  • Fixed exception when using a different axis than 0 for registering stacks

0.2.2

changed

  • License changed to allow distribution on python package repositories

0.2.1

added

  • progress callback function can be supplied to register_stack() and register_transform_stack() functions via the progress_callback that is then called after every iteration (i.e. after each image registration)

changed

  • progress bar output not shown by default, has to be enabled by using the verbose=True parameter in the register_stack() and register_transform_stack() functions

0.2.0

added

  • bilinear transformation

Metadata

Release files for pystackreg 0.2.5

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

Source distribution (sdist)

Source distribution for pystackreg 0.2.5
File Size Uploaded Provenance Actions
pystackreg-0.2.5.tar.gz 3.7 MB Without provenance Details for pystackreg-0.2.5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pystackreg 0.2.5
File Actions
pystackreg-0.2.5-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for pystackreg-0.2.5-cp39-cp39-win_amd64.whl
pystackreg-0.2.5-cp39-cp39-win32.whl CPython 3.9 CPython 3.9 Windows x86-32 Details for pystackreg-0.2.5-cp39-cp39-win32.whl
pystackreg-0.2.5-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for pystackreg-0.2.5-cp38-cp38-win_amd64.whl
pystackreg-0.2.5-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details for pystackreg-0.2.5-cp38-cp38-win32.whl
pystackreg-0.2.5-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for pystackreg-0.2.5-cp37-cp37m-win_amd64.whl
pystackreg-0.2.5-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details for pystackreg-0.2.5-cp37-cp37m-win32.whl
pystackreg-0.2.5-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for pystackreg-0.2.5-cp36-cp36m-win_amd64.whl
pystackreg-0.2.5-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for pystackreg-0.2.5-cp36-cp36m-win32.whl
pystackreg-0.2.5-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details for pystackreg-0.2.5-cp35-cp35m-win_amd64.whl
pystackreg-0.2.5-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details for pystackreg-0.2.5-cp35-cp35m-win32.whl
pystackreg-0.2.5-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details for pystackreg-0.2.5-cp27-cp27m-win_amd64.whl
pystackreg-0.2.5-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details for pystackreg-0.2.5-cp27-cp27m-win32.whl

Total release size: 4.5 MB

Release files / pystackreg-0.2.5.tar.gz

Download URL pystackreg-0.2.5.tar.gz
Size 3.7 MB
Tags Source
SHA-256 checksum
How to use checksums
5b38fb9059d2c5c59a69eb4c74c14bdd5e064552b37babacd239ede1d04b6258
BLAKE2b-256 checksum
How to use checksums
59cc3d86c7129d2fc04150e16d6e053ecc2e3870bb1a83126179422e356df775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

Release files / pystackreg-0.2.5-cp39-cp39-win_amd64.whl

Download URL pystackreg-0.2.5-cp39-cp39-win_amd64.whl
Size 64.9 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
9e5039b2935d26813c58310bde5d8e4653664fef543ac1e4882c53af9ad99aaa
BLAKE2b-256 checksum
How to use checksums
5bb3065ac3a7dcdf7938a8d5f14f40fff59c6f19190cc766dc804665a56c6d4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

Release files / pystackreg-0.2.5-cp39-cp39-win32.whl

Download URL pystackreg-0.2.5-cp39-cp39-win32.whl
Size 56.4 kB
Tags CPython 3.9 Windows x86-32
SHA-256 checksum
How to use checksums
685564843b4bda3e3a351b0b314af7682a55421597a5db63eccd27a6df8b4261
BLAKE2b-256 checksum
How to use checksums
cbc06ccf5e0bf8235d4aae61f883fe41eae1510cfd35ecb5aa8aa2efceb0e3ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

Release files / pystackreg-0.2.5-cp38-cp38-win_amd64.whl

Download URL pystackreg-0.2.5-cp38-cp38-win_amd64.whl
Size 64.9 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
028a28c87cdff2096c9c73afeef1864b6cd979596c2e1d530f18cdcdd90bba67
BLAKE2b-256 checksum
How to use checksums
f8818291fb6dea029ba1c6a8e322bc0de186e2ef709c9ea610c5415ea70169e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release files / pystackreg-0.2.5-cp38-cp38-win32.whl

Download URL pystackreg-0.2.5-cp38-cp38-win32.whl
Size 56.4 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
61b80b098c53ab3223475931807ae756949a292f918083bdae2e46a142b3a1b2
BLAKE2b-256 checksum
How to use checksums
2f38948fa47918ce27a25e72276394254bff1a73574ce388703e09dda1102c34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release files / pystackreg-0.2.5-cp37-cp37m-win_amd64.whl

Download URL pystackreg-0.2.5-cp37-cp37m-win_amd64.whl
Size 64.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
97c92418eec2540dfad1ead92c553edcba0f31786f091ce5ca6d34aac6fc6ddd
BLAKE2b-256 checksum
How to use checksums
480404ad23a3ba146e0bcfee3aa8ccece5638a2f8a734c40c28b55548d9a1b80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / pystackreg-0.2.5-cp37-cp37m-win32.whl

Download URL pystackreg-0.2.5-cp37-cp37m-win32.whl
Size 56.2 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
794c8d6f646c4531f993070283a50dc9f4df0d37ab204440006b5aab1ee11952
BLAKE2b-256 checksum
How to use checksums
7a53ee0b62615ae24307b2e78ce257b26a319ff44a7a79f41028f177ecef6271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / pystackreg-0.2.5-cp36-cp36m-win_amd64.whl

Download URL pystackreg-0.2.5-cp36-cp36m-win_amd64.whl
Size 64.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
b4213884660d061e1ace37165234c67b65edc235c6b23b5e687d1218eeae32a4
BLAKE2b-256 checksum
How to use checksums
9ae9a46f14a25cd2ea5f2b77c0f5a4ffbd3c8d9ed3386fdc4ec8f94c819ddbbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.8

Release files / pystackreg-0.2.5-cp36-cp36m-win32.whl

Download URL pystackreg-0.2.5-cp36-cp36m-win32.whl
Size 56.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
dbbc2d60962093e639dc08369853c3272c55bf938ef9623377491bd26ad6bc3d
BLAKE2b-256 checksum
How to use checksums
fb8457f57d7f447dc90d69e122fb8e47c0b4b051c8bc2b7562d600f118c6866d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.8

Release files / pystackreg-0.2.5-cp35-cp35m-win_amd64.whl

Download URL pystackreg-0.2.5-cp35-cp35m-win_amd64.whl
Size 64.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
5e5e072f18b9dfe56ac9fc8d4fe6c59b641fdf3768a613c84c1bb8863eb9e070
BLAKE2b-256 checksum
How to use checksums
eddbfd528acbd299b05fec9e114af42eb4b3902d25e616f133f6955692ebda47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.5.4

Release files / pystackreg-0.2.5-cp35-cp35m-win32.whl

Download URL pystackreg-0.2.5-cp35-cp35m-win32.whl
Size 56.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
bad97cb3a3fc57e3d2a03247e83afa25f631b15855dcc8769ea74dc3081ea629
BLAKE2b-256 checksum
How to use checksums
5c0b2fd013472d0e8903c1376cc6999e4f2f1d56a0e6239913bda594c244203f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.5.4

Release files / pystackreg-0.2.5-cp27-cp27m-win_amd64.whl

Download URL pystackreg-0.2.5-cp27-cp27m-win_amd64.whl
Size 76.2 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
f55183312eef524156a8a84e5f0bf7de2760e4e225fc5885f13b2ba108edb98d
BLAKE2b-256 checksum
How to use checksums
db0b9b77462a65624f58cbe44ae32aea31e84b2f86cd23a4f445b2b63c33d9f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.6.1 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/2.7.17

Release files / pystackreg-0.2.5-cp27-cp27m-win32.whl

Download URL pystackreg-0.2.5-cp27-cp27m-win32.whl
Size 64.8 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
65ac79f8d2bdd56e0afac477291ca7269ccb8340486bcec17d6930964311912d
BLAKE2b-256 checksum
How to use checksums
dc7bfcbe1de003e9741dd2445b9eb7249d4596a589ac8c33d36d55350c3e22b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.6.1 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/2.7.17

Security for pystackreg 0.2.5

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.

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