Cs 194 Project 1:

Images of the Russian Empire: Colorizing the Produkin-Gorskii Photo Collection

Project Overview

The goal of this project is to align images from the Produkin-Gorskii collection that are split into red, green, and blue channels. I used exhaustive search and pyramid search to find the best displacements for each channel. I also experimented with using edge masks to find best displacements and to perform automated cropping.

Exhaustive Search

We perform a grid search over different x and y offset combinations and compute a SSD metric between the shifted layer and the base layer. We select the offset that results in the lowest SSD.

Pyramid Search

Recursively downsampling the image and computing alignments using exhaustive search over small grids at each level.

Bells and Whistles

I calculated edge masks for each image and use them to calculate SSDs of displaced channels, as well as for cropping after alignment.

Exhaustive Search

In exhaustive search, I searched over a grid of x and y displacements ranging from -15 to 15 pixels. For each displacement, I calculated the SSD between the displaced channel and the base channel. I selected the final displacement as the one that results in the lowest SSD metric.

Cathedral
Blue: Base, Green: (5, 2), Red: (12, 3)
Monastery
Blue: Base, Green: (-3, 2), Red: (3, 2)
Tobolsk
Blue: Base, Green: (3, 3), Red: (6, 3)

Pyramid Search

In pyramid search, we call exhaustive search recursively on downscaled images. I downsample the image 5 times, scaling by a factor of 0.5 each time, to generate 6 levels. Then, I start at the smallest level and run exhaustive search to find the best displacement using a grid from -6 to 6 across both x and y. I use twice the displacement of the previous smaller level in order to shift the current level at each recursive step. At the very end, my displacement returned is a sum of the scaled displacements at each level. Originally, I was not getting good alignment with a recursion depth of 4 and a grid size of -5 to 5, but after I increased to a depth of 5 and grid size of -6 to 6 I got good alignment. For Emir specifically, I had to set the green channel as the base instead of blue to get a good alignment.

Cat
Blue: Base, Green: (77, 23), Red: (165, 30)
Church
Blue: Base, Green: (25, 4), Red: (58, 5)
Emir
Green: Base, Blue: (-49, -24), Red: (57, 17)
Harvesters
Blue: Base, Green: (59, 16), Red: (123, 13)
Icon
Blue: Base, Green: (41, 17), Red: (89, 23)
Lady
Green: Base, Blue: (51, 9), Red: (112, 11)
Lilies
Blue: Base, Green: (46, -6), Red: (117, -28)
Melons
Blue: Base, Green: (81, 10), Red: (178, 13)
Onion Church
Green: Base, Blue: (51, 26), Red: (108, 36)
Self Portrait
Blue: Base, Green: (78, 29), Red: (176, 37)
Three Generations
Blue: Base, Green: (53, 14), Red: (112, 11)
Train
Green: Base, Blue: (42, 5), Red: (87, 32)
Workshop
Green: Base, Blue: (53, 0), Red: (105, -12)

Bells and Whistles

For extra credit, I used Canny Edge Detection to compute edge masks for images. I then use these edge masks instead of the original images when computing SSDs between displaced images and the base. I also use these edge masks to perform automatic cropping of the final aligned images.

Example mask of onion church

For masks, I perform cropping by checking the outer 5% of rows and columns of the mask. For each row and column, I check how many white pixels there are in that row. If the number of white pixels exceeds a threshold value (num_rows/5 for each column and num_cols/8 for each row), then I mark that row. At the end, I set the innermost marked row/col of left, right, top, and bottom as the cropping border. Here are a few examples of images generated using edge masks to calculate SSD, and for automated cropping.

Before Crop: Cathedral
Blue: Base, Green: (5, 2), Red: (12, 3)
After crop: Cathedral
Blue: Base, Green: (5, 2), Red: (12, 3)
Cropping: Left 3 Right 0 Top 12 Bottom 14
Before Crop: Monastery
Blue: Base, Green: (-3, 2), Red: (3, 2)
After Crop: Monastery
Blue: Base, Green: (-3, 2), Red: (3, 2)
Cropping: Left 2 Right 0 Top 3 Bottom 14
Before Crop: Tobolsk
Blue: Base, Green: (3, 3), Red: (6, 3)
After Crop: Tobolsk
Blue: Base, Green: (3, 3), Red: (7, 3)
Cropping: Left 3 Right 2 Top 7 Bottom 14
Before Crop: Cat
Blue: Base, Green: (77, 23), Red: (165, 30)
After Crop: Cat
Blue: Base, Green: (75, 21), Red: (166, 31)
Cropping: Left 31 Right 0 Top 0 Bottom 0
Before Crop: Church
Blue: Base, Green: (25, 4), Red: (58, 5)
After Crop: Church
Blue: Base, Green: (25, 3), Red: (58, -4)
Cropping: Left 3 Right 4 Top 58 Bottom 0
Before Crop: Emir
Green: Base, Blue: (-49, -24), Red: (57, 17)
After Crop: Emir
Green: Base, Blue: (-49, -24), Red: (58, 17)
Cropping: Left 17 Right 24 Top 58 Bottom 49
Before Crop: Harvesters
Blue: Base, Green: (59, 16), Red: (123, 13)
After Crop: Harvesters
Blue: Base, Green: (60, 18), Red: (124, 14)
Cropping: Left 18 Right 0 Top 124 Bottom 0
Before Crop: Icon
Blue: Base, Green: (41, 17), Red: (89, 23)
After Crop: Icon
Blue: Base, Green: (39, 16), Red: (89, 23)
Cropping: Left 23 Right 0 Top 89 Bottom 0
Before Crop: Lady
Green: Base, Blue: (51, 9), Red: (112, 11)
Before Crop: Lady
Green: Base, Blue: (57, 5), Red: (120, 13)
Cropping: Left 4 Right 0 Top 120 Bottom 0
Before Crop: Lilies
Blue: Base, Green: (46, -6), Red: (117, -28)
After Crop: Lilies
Blue: Base, Green: (45, -5), Red: (114, -28)
Cropping: Left 0 Right 28 Top 114 Bottom 0
Before Crop: Melons
Blue: Base, Green: (81, 10), Red: (178, 13)
After Crop: Melons
Blue: Base, Green: (80, 10), Red: (178, 17)
Cropping: Left 17 Right 0 Top 80 Bottom 0
Before Crop: Onion Church
Green: Base, Blue: (51, 26), Red: (108, 36)
After Crop: Onion Church
Green: Base, Blue: (52, 24), Red: (107, 35)
Cropping: Left 35 Right 0 Top 107 Bottom 88
Before Crop: Self Portrait
Blue: Base, Green: (78, 29), Red: (176, 37)
After Crop: Self Portrait
Blue: Base, Green: (77, 29), Red: (175, 37)
Cropping: Left 31 Right 0 Top 77 Bottom 0
Before Crop: Three Generations
Blue: Base, Green: (53, 14), Red: (112, 11)
Before Crop: Three Generations
Blue: Base, Green: (55, 19), Red: (111, 8)
Cropping: Left 19 Right 0 Top 111 Bottom 0
Before Crop: Train
Green: Base, Blue: (42, 5), Red: (87, 32)
After Crop: Train
Green: Base, Blue: (43, 5), Red: (85, 29)
Cropping: Left 29 Right 0 Top 84 Bottom 147
Before Crop: Workshop
Green: Base, Blue: (53, 0), Red: (105, -12)
After Crop: Workshop
Green: Base, Blue: (53, -1), Red: (105, -12)
Cropping: Left 0 Right 1 Top 105 Bottom 0

As you can see, the automated cropping does a good job of cropping out the bands at the edge of the image. Also, using edge masks to compute SSD outputs displacement values that are very close to what pyramid search outputs. Therefore, using edge masks does not necessarily improve performance significantly, but it may make the edges slightly sharper on some images.