Read Image: Firsly, we need to take a glass plate image and divide it into three equal parts, B, G, and R.
Crop the Image Border: Since the edges of the image are blurred, the borders can be cropped by a certain proportion.
Part 1 - Exhaustive Search: To align the parts of low-resolution images, we can use exhaustive search over a window of possible displacements, score each displacement using a matching metric, and output the best one. I used the Sum of Squared Differences (SSD) distance to calculate the score of each displacement. Here are some of the colored low-resolution images.
Part 2 - Pyramid Search: For high-resolution images, exhaustive search would be slow and inefficient. Pyramid search is to scale down the images (reduce resolution), and then start the calculation from the lowest resolution image, apply the result to the next level of image calculation, and finally get the results of the highest resolution image (original image). I implement the pyramid search by using a recursion function, and it takes 15~18s to process each given tif image. Here are some of the colored high-resolution images.
An interesting finding: The alignments of some images will be more accurate when the Green channel is used as the base channel. Here is an example using Emir.tif