Skip to main content

pyStackReg

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 four 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 PyPi. Install it using:

pip install pystackreg

Documentation

The documentation can be found on readthedocs:

https://pystackreg.readthedocs.io/

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

Below is the license of TurboReg/StackReg:

/*====================================================================
| Additional help available at http://bigwww.epfl.ch/thevenaz/turboreg/
|
| You'll be free to use this software for research purposes, but you
| should not redistribute it without our consent. In addition, we expect
| you to include a citation or acknowledgment whenever you present or
| publish results that are based on it.
\===================================================================*/

Metadata

Release files for pystackreg 0.2.1

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.1
File Size Uploaded Provenance Actions
pystackreg-0.2.1.tar.gz 30.3 kB Without provenance Details for pystackreg-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pystackreg 0.2.1
File Actions
pystackreg-0.2.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for pystackreg-0.2.1-cp37-cp37m-win_amd64.whl
pystackreg-0.2.1-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details for pystackreg-0.2.1-cp37-cp37m-win32.whl
pystackreg-0.2.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for pystackreg-0.2.1-cp36-cp36m-win_amd64.whl
pystackreg-0.2.1-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for pystackreg-0.2.1-cp36-cp36m-win32.whl
pystackreg-0.2.1-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details for pystackreg-0.2.1-cp27-cp27m-win_amd64.whl
pystackreg-0.2.1-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details for pystackreg-0.2.1-cp27-cp27m-win32.whl

Total release size: 396.4 kB

Release files / pystackreg-0.2.1.tar.gz

Download URL pystackreg-0.2.1.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4ab1c2cee5233a96faf29de47b8ace3892270f2334a7a3cb49e3369fb2db8fec
BLAKE2b-256 checksum
How to use checksums
2460d845d03364bcb77c4d468c705622061fb4409b773830e01845793ce40d7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp37-cp37m-win_amd64.whl
Size 61.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
c961c5c63d188c9d4a45f56d2a9fe8a22cb90906c39259855d749117ee8fdd1c
BLAKE2b-256 checksum
How to use checksums
80838f6dbdfb30599afe97e909f717b947c70393980521310f7dbe8dbae1902d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp37-cp37m-win32.whl
Size 54.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
3c6d046f18c3cacc6163a54b6ad74f1124822fa0eb27f198354c4eece767ce9c
BLAKE2b-256 checksum
How to use checksums
dab3bb71bf605394f3653dea4ce893fcb4e538e86abe656b0cd5225389a9fb11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp36-cp36m-win_amd64.whl
Size 61.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
ab59923b40be58d3e53e81a507d8d059e85f129c34c78c542483945f994558ba
BLAKE2b-256 checksum
How to use checksums
741b9e9ff1e8aece8d13f29af84cfda6d4bba02f60fcc1baf12118a7f3048ff7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp36-cp36m-win32.whl
Size 54.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
0509f7e0c38efedb9afe75d9d8decd9c7d56f3e1c4b316aea6b7ac93fe485d9e
BLAKE2b-256 checksum
How to use checksums
1c894146fc2bf7fb77b78b5c8bb07bafafea2f3d6a86df93f52b434dd4183407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp27-cp27m-win_amd64.whl
Size 73.2 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
96eb69736882e6d87d6be36a2b603ae5b8e36b09e18e568a429930191580d532
BLAKE2b-256 checksum
How to use checksums
141fc5fcb249adf82cfce13ea74862637f97c67a7502f31daa01b014c39b630b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

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

Download URL pystackreg-0.2.1-cp27-cp27m-win32.whl
Size 61.7 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
b12f3eeddc8da39a09253e9017e6b17e6bdda3dfb3c09728d9d06c03b7587294
BLAKE2b-256 checksum
How to use checksums
7e49b1be3daf3968d71e205d5441484e45a20c98c6ef34907f19d5d5c3d44c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

Security for pystackreg 0.2.1

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