pystackreg

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

https://github.com/glichtner/pystackreg

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 8 committers (25.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.6%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

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

Basic Info
  • Host: GitHub
  • Owner: glichtner
  • License: other
  • Language: C++
  • Default Branch: master
  • Homepage:
  • Size: 5.39 MB
Statistics
  • Stars: 91
  • Watchers: 3
  • Forks: 18
  • Open Issues: 9
  • Releases: 5
Created almost 8 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License

README.rst

pyStackReg
==========

.. start-badges

.. image:: https://github.com/glichtner/pystackreg/actions/workflows/wheels-deploy.yml/badge.svg
    :target: https://github.com/glichtner/pystackreg/actions/workflows/wheels-deploy.yml
    :alt: Build & Test

.. image:: https://readthedocs.org/projects/pystackreg/badge/?version=latest
    :target: https://pystackreg.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. image:: https://badge.fury.io/py/pystackreg.svg
    :alt: PyPI Package latest release
    :target: https://pypi.org/project/pystackreg

.. image:: https://img.shields.io/pypi/pyversions/pystackreg.svg
    :alt: Supported Python Versions
    :target: https://pypi.org/project/pystackreg/

.. image:: https://pepy.tech/badge/pystackreg
    :alt: Downloads
    :target: https://pepy.tech/project/pystackreg/

.. end-badges





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). Note that pyStackReg uses the high quality (i.e. high accuracy) mode of TurboReg that uses cubic spline interpolation for transformation.

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

Known issues
............
- pystackreg (and StackReg/TurboReg) have known issues with processing strongly rotated images (e.g. by ~90°; see https://github.com/glichtner/pystackreg/issues/30 for a workaround).


Installation
------------
The package is available on conda forge and on PyPi.

- Install using **conda**

.. code-block:: python

    conda install pystackreg -c conda-forge

- Install using **pip**

.. code-block:: python

    pip install pystackreg


Documentation
-------------
The documentation can be found on readthedocs:

https://pystackreg.readthedocs.io/

Tutorial
--------
* A tutorial notebook can be found in the `examples/notebooks` folder
  or statically here: https://pystackreg.readthedocs.io/en/latest/tutorial.html

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

.. code-block:: python

    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):


.. code-block:: python

    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:

.. code-block:: python

    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):

.. code-block:: python

    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]):
        out[i, :, :] = tf.warp(img1[i, :, :], tmats[i, :, :], order=3)


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.

Owner

  • Name: Gregor Lichtner
  • Login: glichtner
  • Kind: user
  • Location: Greifswald, Germany
  • Company: University Medicine Greifswald

Researcher at University Medicine Greifswald

GitHub Events

Total
  • Issues event: 3
  • Watch event: 9
  • Push event: 1
  • Fork event: 1
Last Year
  • Issues event: 3
  • Watch event: 9
  • Push event: 1
  • Fork event: 1

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 64
  • Total Committers: 8
  • Avg Commits per committer: 8.0
  • Development Distribution Score (DDS): 0.25
Past Year
  • Commits: 18
  • Committers: 4
  • Avg Commits per committer: 4.5
  • Development Distribution Score (DDS): 0.444
Top Committers
Name Email Commits
Gregor Lichtner g****r@c****e 48
Gregor Lichtner 3****r@u****m 10
Maksim Rakitin m****n@b****v 1
Sebastian Oltmanns s****r@g****m 1
Oren Amsalem o****1@m****l 1
Florian REY 5****s@u****m 1
Lint Action l****n@s****m 1
Patrick Schuenke 3****e@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 28
  • Total pull requests: 14
  • Average time to close issues: 2 months
  • Average time to close pull requests: 8 days
  • Total issue authors: 27
  • Total pull request authors: 7
  • Average comments per issue: 2.18
  • Average comments per pull request: 0.86
  • Merged pull requests: 10
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 6
  • Pull requests: 3
  • Average time to close issues: 11 days
  • Average time to close pull requests: 14 days
  • Issue authors: 5
  • Pull request authors: 2
  • Average comments per issue: 0.83
  • Average comments per pull request: 1.33
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 1
Top Authors
Issue Authors
  • jat255 (2)
  • rpieki (1)
  • JohannaRahm (1)
  • antonyvam (1)
  • uchihatashi (1)
  • FritzKagerer (1)
  • totheDude (1)
  • caviri (1)
  • patquem (1)
  • naranji (1)
  • bastianmorath (1)
  • PikaPei (1)
  • idc9 (1)
  • Helena-todd (1)
  • superwhat1 (1)
Pull Request Authors
  • glichtner (8)
  • orena1 (3)
  • dependabot[bot] (2)
  • mrakitin (1)
  • schuenke (1)
  • florianwns (1)
  • SebastianOltmanns (1)
Top Labels
Issue Labels
question (4) help wanted (2) feature request (2) enhancement (2) wontfix (1)
Pull Request Labels
dependencies (2)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 3,534 last-month
  • Total dependent packages: 14
    (may contain duplicates)
  • Total dependent repositories: 26
    (may contain duplicates)
  • Total versions: 16
  • Total maintainers: 1
pypi.org: pystackreg

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

  • Versions: 11
  • Dependent Packages: 9
  • Dependent Repositories: 25
  • Downloads: 3,534 Last month
  • Docker Downloads: 0
Rankings
Dependent packages count: 1.4%
Dependent repos count: 2.9%
Downloads: 4.3%
Docker downloads count: 4.5%
Average: 5.0%
Stargazers count: 8.2%
Forks count: 8.9%
Maintainers (1)
Last synced: 11 months ago
conda-forge.org: pystackreg

C++ Port of the TurboReg/StackReg ImageJ Plugin. Original code by Philippe Thevenaz (see below). Porting by Gregor Lichtner. 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/

  • Versions: 5
  • Dependent Packages: 5
  • Dependent Repositories: 1
Rankings
Dependent packages count: 10.4%
Dependent repos count: 24.3%
Average: 28.2%
Stargazers count: 37.7%
Forks count: 40.2%
Last synced: 11 months ago

Dependencies

docs/requirements.txt pypi
  • sphinx >=1.3
  • sphinx-rtd-theme *
  • sphinx_autodoc_typehints *
requirements.txt pypi
  • numpy *
  • tqdm *
setup.py pypi
  • numpy *