Now we may want to "align" a particular image at the same angle as the reference image. In the images above, the first image can be assumed to be the “perfect” cover photo, while the second and third images are not very well suited for book cover photos. The image registration algorithm helps us align the second and third images in the same plane as the first.
How does image registration work?
Alignment can be thought of as a simple coordinate transformation. The algorithm works as follows:
- Convert both images to grayscale.
- Match the image elements to be aligned with the reference image and save the coordinates of the corresponding key points. Key points — they are simply selected multiple points that are used to compute the transformation (usually the highlight points), and the — these are histograms of image gradients that characterize the appearance of the key point. In this article, we use the ORB (Oriented FAST and Rotated BRIEF) implementation in the OpenCV library, which provides us with both cue points and their associated descriptors.
- Map cue points between two images. In this post, we are using BFMatcher, which is a brute force method.
BFMatcher.match ()retrieves the best match, while
BFMatcher.knnMatch ()retrieves the top K matches, where K is specified by the user.
- Select best matches and remove noisy matches.
- Find homomorphic transform.
- Apply this transform to the original unaligned image to get the output image.
Image registration applications —
Some of the useful image registration applications include:
- Stitching different scenes (which may or may not have the same camera alignment ) together to form a continuous panoramic image.
- Align camera images to documents with standard alignment to create realistic scanned documents.
- Align medical images for better observation and analysis. >
Below is the code to register an image. We have aligned the second image with a link to the third image.