Package: imgreg2D
Imgreg2DSimple napari based python application to register a 2D image to a template.InstallationYou can instal the code directly from Pypi using:pip install imgreg2dAlternative you can instal directly from thewith:pip install git+https://github.com/BrancoLab/imgreg2D.git --upgradeUSAGETo 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, checkexample.pyor read below:Step 0 - import function and get the imagesfrom 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 imageWhen we will callregisterwe 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 passingnp.ndarraywith image data.Step 1 - define points on reference imageTo define the location of the points used for registration on the reference image (fixed_points) you can useget_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, pressqto close the viewer and proceed to the next step.Step 2 - define points on registering imageNow 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 refinementOnce 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, pressyto complete the analysis (if you're not happy,
pressnand 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 contributionThe original code was part ofCommon-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.