Image registration with Jupyter

Drag your markers and warp

In this example we will register a high resolution RGB image of a Rembrandt drawing (the source image) onto a lower resolution elemental map for iron (the destination image). This is done by drawing four corresponding landmark point pairs in an interactive holoviews widget in this Jupyter notebook. To get started we first need to import matplotlib, holoviews and the ImageRegistratorHelper class and activate the holoviews bokeh extension.

import matplotlib.pyplot as plt 
import holoviews as hv 
from imageregistrationhelper import ImageRegistrationHelper
hv.extension('bokeh')

Then we need to load the two images as arrays into memory using the matplotlib imread() function as follows.

im_src = plt.imread('../demo_data/RP-T-1898-A-3689_highres.png') # source image
im_dst = plt.imread('../demo_data/RP-T-1898-A-3689_FeKa-map-clipped.png') # destination image
fig, [ax0, ax1] = plt.subplots(ncols=2)

ax0.imshow(im_src)
ax0.set_title('Source image')
ax1.imshow(im_dst)
ax1.set_title('Destination image');

Now instantiate ImageRegistratorHelper class and display the interactive canvas. Activate the Point Draw Tool in the menu and in the four corner regions the top and bottom image viewers draw landmark point pairs on corresponding positions.

imreg = ImageRegistrationHelper(im_src, im_dst)
imreg.canvas

If you feel that all points pairs are positioned correctly you can inspect the result by executing the .warp() method.

imreg.warp()

If the result is good you can save the resulting image with the .save() method. The this function returns the image array and corresponding extent for further processing. If you provide an image filename the registered image will be also be saved in your working directory.

imvis_reg_highres, extent = imreg.save('my_registered_image.png')

FUNCTIONS


source

warp


def warp(
    im_src, im_dst, pts_src, pts_dst, keep_scale:bool=True, rgba:bool=True, alpha_color:list=[1, 0, 0]
):

Opencv based homographic registration. Can return transparent overlay (rgba).

Returns: im_warped, extent


source

ImageRegistrationHelper


def ImageRegistrationHelper(
    im_src, im_dst, frame_width:int=400
):

Create interactive holoviews canvas to draw 4 point pairs.