CS 194-26: Spring 2020
Project 1: Colorizing the Prokudin-Gorskii Photo Collection
Yash Agarwal

Overview

For this project, we needed to colorize Sergei Mikhailovich Prokudin-Gorskii's glass plates from the Russian Empire.

Low Res Images - Single Scale Implementation

For the lower resolution images, I used an exhaustive search algorithm as suggested in the project spec. I ran a nested for loop to find the optimal displacements between -15 and 15 for both the x and y axis. The metric I used to align images was Sum of Squared Distances (SSD). I aligned the green and red channel to the blue channels. It works pretty fast and pretty good on the low-resolution images. We see some very good results.

High Res Images - Multiscale Pyramid Implementation

The exhaustive search method is not feasible for high res images as the channel matrices are extremely big. For this I implemented a multiscale pyramid approach which resizes the images by a factor 2 every time for 5 levels. It calculates the optimal displacement at the top most level and then scales it and sends it to the lower level. Then we look over a range of (optimal displacement - 1/scaling_factor, optimal displacement + 1/scaling_factor) to again find the optimal displacement. We repeat this until we reach the bottom most level. To align the image, I used Normalized Cross Correlation as the metric to calculate how close two images are. It is simply the dot product of the two normalized images. I implemented this in the form of a recursive function. Once we find the optimal offsets, I simply align the green and red channels to the blue channel. Finally since we roll the images and actually displace them , we need to crop the borders. I crop the 10% of the image from each side.

Roadblocks

Initially, I faced a lot of problems trying to understand Normalized Cross Correlation. Finally, I stumbled upon this which helped me understand cross correlation and implement the code for it.
Next, I tried to implement Canny Edge Detection. I used the OpenCV library to implement Canny's edge detection. The problem I ran into here was calculating the low and high threshold for deciding edges. I found Otsu's method (here) to help calculate the threshold for finding the edges. I found the edges for each of the RGB channels and then the optimal displacement for the edges. Then, I rolled the original RGB channels

Results (Using Single Scale and Multiscale Pyramid Implementation)

Green Offsets: [5, 2] Red Offsets: [12, 3]
Green Offsets: [3, 3] Red Offsets: [6, 3]
Green Offsets: [-3, 2] Red Offsets: [3, 2]
Green Offsets: [59, 16] Red Offsets: [124, 13]
Green Offsets: [79, 29] Red Offsets: [176, 37]
Green Offsets: [35, 3] Red Offsets: [98, 4]
Green Offsets: [82, 11] Red Offsets: [178, 13]
Green Offsets: [51, 27] Red Offsets: [108, 36]
Green Offsets: [41, 17] Red Offsets: [90, 23]
Green Offsets: [43, 6] Red Offsets: [87, 32]
Green Offsets: [56, 8] Red Offsets: [116, 11]
Green Offsets: [53, 0] Red Offsets: [105, -12]
Green Offsets: [53, 14] Red Offsets: [112, 11]
Green Offsets: [49, 24] Red Offsets: [103, 57]

Custom Images

Green Offsets: [60, 6] Red Offsets: [126, 4]
Green Offsets: [27, 9] Red Offsets: [63, 10]
Green Offsets: [33, 14] Red Offsets: [86, 23]
Green Offsets: [24, 21] Red Offsets: [60, 29]

Bells and Whistles

I tried to implement three different approaches.

1) Canny Edge Detection: To improve the quality of images, I used a different feature to align the images. Instead of aligning the original RGB channels I first detected the edges in the channels and then aligned the channels. This significantly improved Emir's quality.

2) Automatic Contrasting: I also implemented automatic contrasting to make the images look better. I used the rescale intensity function with an out range of 5th percentile and the 95th percentile.

3) Automatic Cropping: My code also automatically crops 10% from each side of the image.

Results Using Edge Detection and Automatic Contrasting

Green Offsets: [60, 18] Red Offsets: [117, 11]
Green Offsets: [78, 29] Red Offsets: [177, 32]
Green Offsets: [34, 3] Red Offsets: [97, 4]
Green Offsets: [80, 10] Red Offsets: [174, 13]
Green Offsets: [52, 24] Red Offsets: [107, 34]
Green Offsets: [42, 16] Red Offsets: [90, 22]
Green Offsets: [41, 8] Red Offsets: [84, 28]
Green Offsets: [57, 9] Red Offsets: [119, 12]
Green Offsets: [50, -2] Red Offsets: [99, -13]
Green Offsets: [47, 13] Red Offsets: [106, 16]
Green Offsets: [48, 19] Red Offsets: [104, 40]

Custom Images After Edge Detection and Automatic Contrasting

Green Offsets: [58, 7] Red Offsets: [124, 5]
Green Offsets: [26, 9] Red Offsets: [62, 9]
Green Offsets: [34, 12] Red Offsets: [83, 22]
Green Offsets: [26, 10] Red Offsets: [60, 28]

Credit for the Website Template: Megan Lee