Skip to main content

Imgreg2D

Simple napari based python application to register a 2D image to a template.

Installation

You can instal the code directly from Pypi using:

pip install imgreg2d

Alternative you can instal directly from the github repository with:

pip install git+https://github.com/BrancoLab/imgreg2D.git --upgrade

USAGE

To register an image to a template the user needs to specify the location of a set of points (>3, ideally at least 6) on both the reference and the registering image. These data are then used to compute an affine matrix which is then used to warp the registering image so that it matches the template.

For an example of how to perfom image registration, check example.py or read below:

Step 0 - import function and get the images

from imgreg2D.register import register
from imgreg2D.points import get_fixed_points

reference = 'media/original.jpg' # <- path to reference image
registering = 'media/rotated.jpg' # <- path to registering image

When we will call register we will have to pass the the reference and registering images. This can be done by passing file paths like in the code above or by passing np.ndarray with image data.

Step 1 - define points on reference image

To define the location of the points used for registration on the reference image (fixed_points) you can use get_fixed_points. If you already know the location of these points (e.g. because you already used the same template image), you can skip this step.

points = get_fixed_points(reference)

Once you've clicked on all the points you need, press q to close the viewer and proceed to the next step.

Step 2 - define points on registering image

Now you will have to click on the corresponding set of points in the registering image so that the affine transform can be computed. Remember, the order in which the points are defined is important: the first point you clicked in Step 1 has to correspond to the first point you'll define now. For this reason, you're shown a copy of your reference image with the location and sequence of fixed points. Once you've defined all the registering points the editor will close automatically and the analysis will proceed to the next step.

To start defining the registering points call:

register(reference, registering, fixed_points = points)

Note: if you already have a transform matrix (e.g. from a previous run of the registering step), you can skip this step. To skip Step 2 simply call:

warped_img, warp_mtx = register(reference, registering, warp_mtx = warp_mtx)

Note2: when calling register you can decide if you want to save the warp matrix or not. This could be use to save time the next time you need to register an image.

Step 3 - interactive refinement

Once you've defined the location of the registering points, the code will compute the affine transform (warp_mtx) and register your image. At this point another napari viewer will open which you can use to refine the accuracy of your transformation using the following hotkeys:

############################################################
##                REFINEMENT HOT KEYS                     ##
##                                                        ##
##    TRANSLATIONS                                        ##
##   ------------------------------------------------     ##
##      'a' -> negative x translation                     ##
##      'w' -> positive y translation                     ##
##                                                        ##
##      's' -> negative y translation                     ##
##      'd' -> positive x translation                     ##
##                                                        ##
##    SCALING                                            ##
##   ------------------------------------------------     ##
##      'r' -> positive x scaling                         ##
##      'f' -> negative x scaling                         ##
##                                                        ##
##      't' -> positive y scaling                         ##
##      'g' -> negative y scaling                         ##
##                                                        ##
##    SHEARS                                              ##
##   ------------------------------------------------     ##
##      'z' -> positive x shear                           ##
##      'x' -> negative x shear                           ##
##                                                        ##
##      'c' -> positive y shear                           ##
##      'v' -> negative y shear                           ##
##                                                        ##
############################################################

Once you're happy with your results, press y to complete the analysis (if you're not happy, press n and you can try again from Step 2). After Step 3 you'll have your registered image (warped_img) and your affine transform matrix (warp_mtx), enjoy!

Credit and contribution

The original code was part of Common-Coordinates-Behaviour (credit: Philip Shamash). The code was adapted to work with Napari.

Contributions are welcome! Just send a PR or open an issue as neeeded.

Metadata

Release files for imgreg2D 0.0.0.2

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

Source distribution (sdist)

Source distribution for imgreg2D 0.0.0.2
File Size Uploaded
imgreg2D-0.0.0.2.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for imgreg2D 0.0.0.2
File Interpreter ABI Platform
imgreg2D-0.0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / imgreg2D-0.0.0.2.tar.gz

Download URL imgreg2D-0.0.0.2.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cd27f06798259d8415bb0f07952dc187b0f98afd5f399c958196cbdaa261aa29
BLAKE2b-256 checksum
How to use checksums
6d34e59f156a9c92eecbabba0bdfc552fe4c6cf94a0c2cdf899e4afef45c1efa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / imgreg2D-0.0.0.2-py3-none-any.whl

Download URL imgreg2D-0.0.0.2-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6779f733cfc75aa5f18588010115d7ba595629c3eec96ba72f4b664893bdd9f5
BLAKE2b-256 checksum
How to use checksums
b547680dfec15723234b4a929c1d3623f10bc9353a81ce66b3ab27b2f50db237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.0.2 This release

2 release files

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