# Homography Calculation

## [Final Year Project] FPGA based Image Mosaicing using AI (log #7)

### Homography

Homography gives the relation between the similar keypoints in the two images.

Homography matrix of the second image with respect to the first image is used to warp the second image into a global coordinate frame with respect to the first image.

$\begin{bmatrix} x2\\ y2\\ 1 \end{bmatrix}= H_{3 x 3}\begin{bmatrix} x1\\ y1\\ 1 \end{bmatrix}$

$\begin{bmatrix} x2\\ y2\\ 1 \end{bmatrix}= \begin{bmatrix} h1 & h2 & h3\\ h4 & h5 & h6\\ h7 & h8 & 1 \end{bmatrix} \begin{bmatrix} x1\\ y1\\ 1 \end{bmatrix}$

H is the 3 x 3 Homography Matrix where
h3 – Translation on X Axis
h6 – Translation on Y Axis
h1,h2,h4,h5 – Scaling and Rotation
h7,h8 – Horizontal and Vertical Distortion

### RANSAC

We make use of the RANSAC algorithm to determine the Homography Matrix.

Ideally, we can use Direct Linear Transformation on 4 Best Match Points to determine the homography. However, since the matches are not always perfect and there are chances of imperfect matches a robust algorithm such as RANSAC is used.

RANSAC stands for Random Sample Consensus. In every RANSAC iteration, several matched pairs of points are randomly chosen to produce a best-fit transformation matrix, and the pairs which agree with the matrix are taken as inliers. After a number of iterations, the transform that satisfies the most number of inlier pairs is taken as the final result.

### Code For Calculating Homography

The following code is in continuation after determining Keypoints and Matches.

It uses keypoints from ‘good’ matches to determine the Homography.

0