Skip to main content

Image registration tool (python implementation of the ImageJ/FIJI Plugin TurboReg/StackReg)

Project description

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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pystackreg-0.2.3-cp39-cp39-win_amd64.whl (64.9 kB view details)

Uploaded CPython 3.9Windows x86-64

pystackreg-0.2.3-cp39-cp39-win32.whl (56.3 kB view details)

Uploaded CPython 3.9Windows x86

pystackreg-0.2.3-cp38-cp38-win_amd64.whl (64.8 kB view details)

Uploaded CPython 3.8Windows x86-64

pystackreg-0.2.3-cp38-cp38-win32.whl (56.3 kB view details)

Uploaded CPython 3.8Windows x86

pystackreg-0.2.3-cp37-cp37m-win_amd64.whl (64.7 kB view details)

Uploaded CPython 3.7mWindows x86-64

pystackreg-0.2.3-cp37-cp37m-win32.whl (56.2 kB view details)

Uploaded CPython 3.7mWindows x86

pystackreg-0.2.3-cp36-cp36m-win_amd64.whl (64.7 kB view details)

Uploaded CPython 3.6mWindows x86-64

pystackreg-0.2.3-cp36-cp36m-win32.whl (56.2 kB view details)

Uploaded CPython 3.6mWindows x86

pystackreg-0.2.3-cp35-cp35m-win_amd64.whl (64.7 kB view details)

Uploaded CPython 3.5mWindows x86-64

pystackreg-0.2.3-cp35-cp35m-win32.whl (56.2 kB view details)

Uploaded CPython 3.5mWindows x86

pystackreg-0.2.3-cp27-cp27m-win_amd64.whl (76.2 kB view details)

Uploaded CPython 2.7mWindows x86-64

pystackreg-0.2.3-cp27-cp27m-win32.whl (65.0 kB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file pystackreg-0.2.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 64.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for pystackreg-0.2.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7ec5e26b34adc8d23c43b5a8a8009beac716df85d4ef65d5f2799e152b268a3e
MD5 8ae6422957de33ac1674f0af9da3268d
BLAKE2b-256 ee6899c25dc1ed4334fa4b53c123c249e43a0ce4ebaab5e0cca29b2087c0c68b

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp39-cp39-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp39-cp39-win32.whl
  • Upload date:
  • Size: 56.3 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for pystackreg-0.2.3-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 8fb5167fcc9777d93b5dfe1843b1d4186d06e9c576cb6875e607ee38eccca4ee
MD5 9c2e2a9c03951694afa013693e80cf49
BLAKE2b-256 e4f6a3b4cbb5dcd0b4f1fadd9454ac3cb5a31c904eb74221c458ed8e06023e3a

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 64.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for pystackreg-0.2.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 71785b59c3e4c0e722d32e8ec5522911a46e148b9168ae860f320d95af013660
MD5 7668688a49773435905184606bfa45f2
BLAKE2b-256 22168741c83faf97fa0f4be8a6b30102dd8d3d9c022c152245567b7cdbe23cb5

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp38-cp38-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp38-cp38-win32.whl
  • Upload date:
  • Size: 56.3 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for pystackreg-0.2.3-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 42779da700f8b12edde471617737f11e8f751321bdb3d85364992423f84f16e3
MD5 73dc2c639fa588e9fc404ebd50b14726
BLAKE2b-256 a815534274a056fcb8ca74d147ac08d67f57d6f18078c547d65cfa288478795b

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 64.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for pystackreg-0.2.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a45ee9ecfdf54647b5b62c19f33dd4f9e2b3a19777fd9feeba879e3657801073
MD5 3960f48068535bcd21ca14347215d504
BLAKE2b-256 a841afc350a71e1e5d92da91437bf4770a4e2adf57c9905dfabf4b06af0dab88

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp37-cp37m-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for pystackreg-0.2.3-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 90cc7fb7983503b5d0e3aa6161dac100036d72a3f3c9632b22741cbd22a9b71e
MD5 d392d498e6d9ec1abaff6775a694e593
BLAKE2b-256 a65912b4026996a8ac060d31db74534ecfa7007544ec618a9362661e80424732

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 64.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.8

File hashes

Hashes for pystackreg-0.2.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 57aca3ce2f9ead5e8d6fcc97ca5a3ac504eef5cb56af48613aa778d96365170f
MD5 7c5197e6f75ab4f5440eb11bbb4e072c
BLAKE2b-256 f74d81a12afc8116b7786d5501b38eafd9aebfb5bd26aef944ff744052747f9d

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp36-cp36m-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.8

File hashes

Hashes for pystackreg-0.2.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 7833cb923dee4d0aa3f1d6a12eb3edad70001ee02b1f4622698dca559e0ec6c2
MD5 903c3257e08b904ef9044c9d69d1a9cf
BLAKE2b-256 2fbf8528d033e7f47474a9794476f7549829803f78601918450771e3b352d05c

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 64.7 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using 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.55.1 CPython/3.5.4

File hashes

Hashes for pystackreg-0.2.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 37e272701e0bd8edad52ea6de674d0db816b45bf78b40921dee497b5be7f6b4c
MD5 8e10a5a3246284ba96bc97c52339dea0
BLAKE2b-256 6eb75d6837a05d5d98ac18f25a32d1e0c22b046acd15e6f9a2d62225f2711840

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp35-cp35m-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using 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.55.1 CPython/3.5.4

File hashes

Hashes for pystackreg-0.2.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 46735a096e530e5e74464a597cefcc92bc657482fad3cee3d66084a8c8327f1f
MD5 700d693d8e8958d53e92bf3fa750e9cd
BLAKE2b-256 81d7a83f3e1b92341d557d8eddebdacbfabf140a2e5efc3e488348c29fb96539

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 76.2 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using 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.55.1 CPython/2.7.17

File hashes

Hashes for pystackreg-0.2.3-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 ae68c0edf70768cb4e17b531839fe93be804c2c6eaef051698947784567d209f
MD5 4a6d538794e6e0f2b358ae0f4fb30432
BLAKE2b-256 d347f8733b90efa22ea55e16a550b6deb571f68b7be859fc3d21bf258fb01697

See more details on using hashes here.

File details

Details for the file pystackreg-0.2.3-cp27-cp27m-win32.whl.

File metadata

  • Download URL: pystackreg-0.2.3-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 65.0 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using 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.55.1 CPython/2.7.17

File hashes

Hashes for pystackreg-0.2.3-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 250cd32941d8273f91764a6daa18509d11d2802d5bb737766c632382ad5333b6
MD5 d677488e679f9ef1d6b6e482b4e19d48
BLAKE2b-256 a56e40290770c5ba01773886ec6d3429a2c07ec703b395331d02f93933afd504

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page