# CS 194-26: Project 1¶

By: Calvin Chen

In this project, we explored different algorithms towards constructing color images from digitzed Prokudin-Gorskii glass plate images. These are split into three image channels-- red, blue, and green-- and were overlayed ontop of each other to render the color images you see below.

## Lower Quality Images (JPGs)¶

For these kinds of images, they tended to be of lower resolution, meaning naive approaches were more easily accessible. By applying an iterative process over a 30x30 grid of different options (-15 to 15 for both x and y), I was able to determine which rolled overlay of green/red image channels over the blue channel maximized the NCC (normalized cross correlation) in order to determine which offsets were best used for the different color channels. Afterwards, the three color channels were stacked onto each other to reconstruct a color image.

Additionally, in order to focus the images on the content rather than the edges, I cropped around 6% from all sides in order to make sure that the discoloration of the edges wouldn't influence the bulk of the image.

## Higher Quality Images (TIFs)¶

For these larger, higher crisp images, I implemented a recursive image pyramid technique that maximized the NCC between green/blue and red/blue to determine, with increasing accuracy, which offsets were best used for the green and red color channels to overlay ontop of the blue color channel.

The way I implemented my technique was as follows:

1. Resize the image to a smaller size, until it reached the base case where either the height or width was less than 500 pixels.
2. Determine which rolling offset of the green and red color channels ontop of the blue color channel resulted in the maximum NCC value.
3. Once these optimal values were found, the were recursively passed up so that each subsequent, larger level would be able to search from a range of (optimal - 1) / alpha to (optimal + 1) / alpha, where optimal was the optimal x or y value offset for the color channel, and alpha was the resize factor.
4. Return to the original resolution, at which the optimal values for x and y offsets for both color channels and determined.

This resulted in a gradual search towards a local (and often global) maxima from the NCC between the green and blue or the red and blue color channels.

## Errors¶

For some images, the translations were still blurry. These images were typically the .tif images, meaning that the recursive image pyramid technique that maximized the NCC was used, meaning that these slight blurs often arose from the fact that the search found local maxima rather than global maxima.

## Translated Images¶

Offsets are listed in (x, y) coordinates.

### cathedral.jpg¶

Green offset: (2, 5)

Red offset: (3, 12)

### monastery.jpg¶

Green offset: (2, -3)

Red offset: (2, 3)

### tobolsk.jpg¶

Green offset: (3, 3)

Red offset: (3, 6)

### harvesters.tif¶

Green offset: (16, 59)

Red offset: (13, 124)

### emir.tif¶

Green offset: (24, 49)

Red offset: (44, 48)

Green offset: (9, 47)

Red offset: (11, 113)

### melons.tif¶

Green offset: (10, 82)

Red offset: (11, 134)

### onion_church.tif¶

Green offset: (26, 51)

Red offset: (36, 108)

### self_portrait.tif¶

Green offset: (28, 78)

Red offset: (0, 134)

### three_generations.tif¶

Green offset: (14, 53)

Red offset: (11, 112)

### workshop.tif¶

Green offset: (0, 52)

Red offset: (-12, 104)

### train.tif¶

Green offset: (5, 42)

Red offset: (31, 87)

### castle.tif¶

Green offset: (3, 35)

Red offset: (4, 98)

### icon.tif¶

Green offset: (17, 40)

Red offset: (23, 89)

## Custom pictures¶

### beach.jpg¶

Green offset: (1, 2)

Red offset: (3, 9)

### building.jpg¶

Green offset: (0, 5)

Red offset: (-1, 11)

### tree.jpg¶

Green offset: (-10, -4)

Red offset: (-9, 2)