# Image registration using python

As per wikipedia, ‘Image registration is the process of transforming different sets of data into one coordinate system’. Simply put, image registration is comparing images with a base image and quantifying the changes. For example when a video is streamed, we would like to find out whether the camera is changing its position, and if so, how do you correct it.

We will look at a snippet written in python which compares two images and returns a homography matrix which relates both the images.

A homography matrix is a 3×3 matrix which decides the transformation between two set of coordinate systems.Mathematically, if A is a set of coordinates in one space and B is a set of corresponding coordinates in another space, then

$A = HB$

Wher H is our homography matrix.

To calculate our homography matrix,we need a set of corresponding points in the two spaces. For this, SIFT(Scale Invariant Feature Transform) is used. SIFT generates a set of ‘interest’ points which can be used for tracking an image.

Once we get the corresponding points, we can calculate the homography matrix. But we need a good algorithm which will pick the necessary points and discard the outliers. To implement this, we use the RANSAC algorithm. RANSAC(RANdom SAmple Consensus) algorithm picks a minimum number of points from a given set and estimates the model. It then takes into account more points from the set which closely fit the model and then calculates the error in the estimated model. This is done for a predefined number of times to get a good model. This model ensures that only inliers are included and outliers are not taken into account.

Using SIFT implementation in python and calculation of homography matrix in python, we apply a RANSAC algorithm to find the homography matrix and change the first image accordingly so that it matches the orientation of the second image.

You can find the source code here:

Python image registration

For further study:
1. Image registration
2. Scale Invariant Feature Transform
3. RANSAC

Note: SIFT is a patented technique by David Lowe. It is protected by the following patents:
Method and apparatus for identifying scale invariant features in an image and use of same for locating an object in an image
David G. Lowe, US Patent 6,711,293 (March 23, 2004). Provisional application filed March 8, 1999. Asignee: The University of British Columbia

## 3 thoughts on “Image registration using python”

1. Jean Baptiste of Institut Astrophysique de Paris is using pyimreg package for his project on Astronomy. Good news for me that someone has found my package useful 🙂

• SIFT user says:

Dear Vishwanath1991,
I am trying to run your code in Linux, but it yields errors. In particular, there seems to be an issue with the creation and later reading of the “processed” file. Could you please check your code and make sure that it works? Thank you very much for your great work.

• Hello,
I tried running the code by cloning my repository separately and then copying a stock sift executable I had. You might have run into the same error as I ran immediately. Permission denied to execute sift and hence IndexError when processing the descriptor files. To overcome this, please change the permission of the sift file. To do so,
`\$ chmod 777 sift`
That should work.