# CS-194-26: Intro to Computer Vision and Computational Photography

## Overview

In this project, we take the RGB glass plate negatives taken by Sergei Mikhailovich Prokudin-Gorskii in the early 1900s of the Russian Empire and attempt to produce color images by aligning the red and green channels of an image with the blue channel.

## Low Resolution Images

For the smaller images that are roughly (300 x 300) pixels, I used a naive exhaustive search algorithm that tried all displacements between -15 and 15 pixels both horizontally and vertically and chose the (x, y) displacement that minimized the Sum of Squared Difference (SSD) between the aligned red and green channels and the blue channel. Additionally, I cropped approximately 10% (300 pixels) of the image on all sides to optimize alignment for internal pixels since pixels on the border are more difficult to align to. Finally, I stacked the aligned red channel, alligned green channel, and the blue channel to create the color image.

Because the low resolution images have a fairly small search space, the naive exhaustive search algorithm works well and produces sharp images in a couple of seconds.

Displacements are given by (Vertical, Horizontal)

cathedral.jpg:
Red: (12, 3)
Green: (5, 2)

monastery.jpg:
Red: (3, 2)
Green: (-3, 2)

tobolsk.jpg:
Red: (6, 3)
Green: (3, 3)

## High Resolution Images

For the larger images that are between 3000 and 4000 pixels on both sides, the naive exhaustive search algorithm is extremely inefficient and creates poor color images. Searching between displacements of (-30, 30) pixels on cathedral.jpg, for example, took 12 minutes. Instead, I use an image pyramid algorithm to approximate and scale the optimal displacement from coarser representations of the image (roughly 200x200) where the displacement search space is much smaller. The displacement given by the smaller representations of the image are recursively scaled and updated until we are the size of the original image. For the image pyramid algorithm, I used a five (5) level pyramid with a scale factor of 2.

This algorithm has drastically better runtime than the naive exhaustive search algorithm and produced clear images. The only image that shows slight blurrinesss is icon.jpg, most likely because the search space was not expansive enough in the coarser images and yielded bad approximations for initial displacement values.

Displacements are given by (Vertical, Horizontal)

castle.tif:
Red: (96, 3)
Green: (32, 3)

emir.tif:
Red: (89, 44)
Green: (49, 20)

harvesters.tif:
Red: (121, 12)
Green: (57, 20)

icon.tif:
Red: (89, 20)
Green: (41, 20)

Red: (113, 11)
Green: (49, 11)

melons.tif:
Red: (161, 11)
Green: (81, 11)

onion_church.tif:
Red: (105, 35)
Green: (49, 27)

self_portrait.tif:
Red: (160, 35)
Green: (80, 27)

three_generations.tif:
Red: (105, 28)
Green: (57, 12)

train.tif:
Red: (89, 28)
Green: (41, 4)

workshop.tif:
Red: (105, -12)
Green: (49, 4)

## Other Images from the Prokudin-Gorskii collection

Below are composed color images of other images from the Prokudin-Gorskii collection

tower.tif:
Red: (105, 28)
Green: (57, 12)

mountain.tif:
Red: (89, -29)
Green: (41, -13)

water.tif:
Red: (128, 3)
Green: (40, 3)

## Bells and Whistles: Automatic White Balancing

Some of the color images appear "faded" because we know that certain objects in the picture should be brighter than they appear. Here, I apply automatic white balancing on the color image produced by the image pyramid algorithm by identifying the brightest pixel in the image and finding the necessary scaling to make that pixel white. All of other pixels in the image are brightened by the same scaling.

Automatic white balancing yields fairly strong improvements over tower.tif and mountain.tif because the original images have pixels that are near-white that should observably be close to completely white. It's hard to see any difference in workshop.tif, however, since the brightest pixel is already extremely close to white(the light coming into the windows)

Images on the left are the original images, Images on the right are the original images with automatic white balancing applied.