CS 194 - Project 1: Images of the Russian Empire:

Overview

The goal of this assignment is to take the digitized Prokudin-Gorskii glass plate images and, using image processing techniques, automatically produce a color image with as few visual artifacts as possible. In order to do this, I extracted the three color channel images, cropped off the thick borders, and aligned them so that they form a single RGB color image, and placed them on top of each other.

Code

Location

The code for this project is contained in the ipython notebook in the file titled "notebook_proj1.ipynb" and will process the named images in the "images" folder, returning the single RGB color images in the "transformed" folder.

Bells & Whistles

I implemented four different variants of this image processing method.

This is because I used two separate objective functions to minimize.

  1. The negative of the cross correlation
  2. The sum of squared distance

And two distinct features with which to represent the photos.

  1. This pixel brightness
  2. The gradient (relative contrast to nearby pixels) of pixel brightness.

Mixing and matching these, I found that in general, the sum of squared distance used on the gradient of the images resulted in the best aligned for my algorithm.

Transformed Pictures (w/ gradient and sum of squared distance)

Offsets for green and red

'cathedral.jpg': {'g_offset': {'x': 2, 'y': -11}, 'r_offset': {'x': 10, 'y': -18}}

'emir.tif': {'g_offset': {'x': 22, 'y': -99}, 'r_offset': {'x': -228, 'y': -142}}

'harvesters.tif': {'g_offset': {'x': 16, 'y': -88}, 'r_offset': {'x': 14, 'y': -172}}

'icon.tif': {'g_offset': {'x': 16, 'y': -111}, 'r_offset': {'x': 23, 'y': -211}}

'lady.tif': {'g_offset': {'x': 8, 'y': -93}, 'r_offset': {'x': 11, 'y': -180}}

'melons.tif': {'g_offset': {'x': 18, 'y': -68}, 'r_offset': {'x': 14, 'y': -124}}

'monastery.jpg': {'g_offset': {'x': 2, 'y': -19}, 'r_offset': {'x': 2, 'y': -29}}

'onion_church.tif': {'g_offset': {'x': 24, 'y': -98}, 'r_offset': {'x': 34, 'y': -193}}

'self_portrait.tif': {'g_offset': {'x': 30, 'y': -70}, 'r_offset': {'x': 38, 'y': -128}}

'three_generations.tif': {'g_offset': {'x': 18, 'y': -93}, 'r_offset': {'x': 12, 'y': -184}}

'tobolsk.jpg': {'g_offset': {'x': 3, 'y': -13}, 'r_offset': {'x': 3, 'y': -26}}

'train.tif': {'g_offset': {'x': 1, 'y': -111}, 'r_offset': {'x': 28, 'y': -216}}

'village.tif': {'g_offset': {'x': 13, 'y': -86}, 'r_offset': {'x': 84, 'y': -134}}

'workshop.tif': {'g_offset': {'x': -4, 'y': -98}, 'r_offset': {'x': -14, 'y': -193}}}

Success Pictures

Wow these are some beautiful pictures, especially considering their age!

Problem Pictures

Both cathedral.jpg and emir.tif failed to align well. I believe the picture of Emir was taken with varying brightnesses and affected the contrast between pixel values slightly, which may have caused the disalignement. Cathedral is just somewhat blurry, but not too far off perfect alignment. These could both be the result of poor border cropping, which makes it easier to find a higher sum of squared distance for misalignment where borders are still crossing over. It may have also failed because the relative contrast of pixels was actually pretty consistent in a lot of places. Photos with significant spaces dominated by one color can sometimes get a bit misaligned by my algorithm and find themselves stuck at a local minimum.

Transformed Pictures (w/o gradient and w/ sum of squared distance)

Offsets for green and red

'cathedral.jpg': {'g_offset': {'x': 0, 'y': -11}, 'r_offset': {'x': 2, 'y': -19}}

'emir.tif': {'g_offset': {'x': 25, 'y': -101}, 'r_offset': {'x': -220, 'y': -143}}

'harvesters.tif': {'g_offset': {'x': 18, 'y': -86}, 'r_offset': {'x': 12, 'y': -169}}

'icon.tif': {'g_offset': {'x': 17, 'y': -110}, 'r_offset': {'x': 22, 'y': -210}}

'lady.tif': {'g_offset': {'x': 8, 'y': -92}, 'r_offset': {'x': 10, 'y': -186}}

'melons.tif': {'g_offset': {'x': 10, 'y': -66}, 'r_offset': {'x': 13, 'y': -121}}

'monastery.jpg': {'g_offset': {'x': 1, 'y': -18}, 'r_offset': {'x': 0, 'y': -26}}

'onion_church.tif': {'g_offset': {'x': 26, 'y': -99}, 'r_offset': {'x': 38, 'y': -194}}

'self_portrait.tif': {'g_offset': {'x': 24, 'y': -78}, 'r_offset': {'x': 37, 'y': -126}}

'three_generations.tif': {'g_offset': {'x': 14, 'y': -95}, 'r_offset': {'x': 12, 'y': -183}}

'tobolsk.jpg': {'g_offset': {'x': 3, 'y': -12}, 'r_offset': {'x': 0, 'y': -25}}

'train.tif': {'g_offset': {'x': 5, 'y': -105}, 'r_offset': {'x': 33, 'y': -214}}

'village.tif': {'g_offset': {'x': 10, 'y': -89}, 'r_offset': {'x': 23, 'y': -141}}

'workshop.tif': {'g_offset': {'x': 2, 'y': -96}, 'r_offset': {'x': -10, 'y': -199}}

Success Pictures

Wow these are some even more delightful pictures, especially considering their age!

Problem Pictures

When using the sum of squared distances for the pixel brightness instead of the gradient, the accuracy of Cathedral went up and it became much better. Unfortunately, Emir is still having trouble here. Monastery also looks a little bit blurrier than before unfortunately. Unlike gradient, this method looks purely at pixel brightness, not gradient or relative brightness to surroundings. As a result, pictures with many similar colors spread out like monastery and emir have a lot of trouble getting locked into place.

Transformed Pictures (w/ gradient and w/ cross correlation)

Offsets for green and red

'cathedral.jpg': {'g_offset': {'x': 2, 'y': -11}, 'r_offset': {'x': 10, 'y': -18}}

'emir.tif': {'g_offset': {'x': 22, 'y': -99}, 'r_offset': {'x': -228, 'y': -142}}

'harvesters.tif': {'g_offset': {'x': 16, 'y': -88}, 'r_offset': {'x': 14, 'y': -172}}

'icon.tif': {'g_offset': {'x': 16, 'y': -111}, 'r_offset': {'x': 23, 'y': -211}}

'lady.tif': {'g_offset': {'x': 8, 'y': -93}, 'r_offset': {'x': 11, 'y': -180}}

'melons.tif': {'g_offset': {'x': 18, 'y': -68}, 'r_offset': {'x': 14, 'y': -124}}

'monastery.jpg': {'g_offset': {'x': 55, 'y': -204}, 'r_offset': {'x': 2, 'y': -29}}

'onion_church.tif': {'g_offset': {'x': 24, 'y': -98}, 'r_offset': {'x': 34, 'y': -193}}

'self_portrait.tif': {'g_offset': {'x': 30, 'y': -70}, 'r_offset': {'x': 38, 'y': -128}}

'three_generations.tif': {'g_offset': {'x': 18, 'y': -93}, 'r_offset': {'x': 12, 'y': -184}}

'tobolsk.jpg': {'g_offset': {'x': 3, 'y': -13}, 'r_offset': {'x': -2, 'y': -26}}

'train.tif': {'g_offset': {'x': 1, 'y': -111}, 'r_offset': {'x': 28, 'y': -216}}

'village.tif': {'g_offset': {'x': 13, 'y': -86}, 'r_offset': {'x': 84, 'y': -134}}

'workshop.tif': {'g_offset': {'x': -4, 'y': -98}, 'r_offset': {'x': -14, 'y': -193}}

Success Pictures

Wow these are some splendid pictures, especially considering their age!

Problem Pictures

When using the cross correlation for the gradient instead of the sum of squared distances, the accuracy of Cathedral and Emir were still poor. Tobolsk and Village are a little bit blurry now and Monastery looks utterly ridiculous. If it is the good, the bad, and the ugly then Tobolsk, Village, Cathedral, and Emir are bad and Monastery is U G L Y! Monastery is likely ugly because of all the different shapes with the same color are still similarly sized. Cropping poorly could also be an issue, as indicated by stripes of color across some of the blurry photos.

Transformed Pictures (w/o gradient and w/ cross correlation)

Offsets for green and red

<'cathedral.jpg': {'g_offset': {'x': 4, 'y': -10}, 'r_offset': {'x': 3, 'y': -22}}

'emir.tif': {'g_offset': {'x': 24, 'y': -102}, 'r_offset': {'x': -223, 'y': -142}}

'harvesters.tif': {'g_offset': {'x': 15, 'y': -85}, 'r_offset': {'x': 16, 'y': -170}}

'icon.tif': {'g_offset': {'x': 14, 'y': -109}, 'r_offset': {'x': 22, 'y': -211}}

'lady.tif': {'g_offset': {'x': 10, 'y': -93}, 'r_offset': {'x': 12, 'y': -182}}

'melons.tif': {'g_offset': {'x': 9, 'y': -68}, 'r_offset': {'x': 12, 'y': -123}}

'monastery.jpg': {'g_offset': {'x': 3, 'y': -19}, 'r_offset': {'x': 3, 'y': -28}}

'onion_church.tif': {'g_offset': {'x': 28, 'y': -102}, 'r_offset': {'x': 38, 'y': -196}}

'self_portrait.tif': {'g_offset': {'x': 26, 'y': -76}, 'r_offset': {'x': 38, 'y': -127}}

'three_generations.tif': {'g_offset': {'x': 15, 'y': -92}, 'r_offset': {'x': 11, 'y': -183}}

'tobolsk.jpg': {'g_offset': {'x': 2, 'y': -16}, 'r_offset': {'x': 3, 'y': -28}}

'train.tif': {'g_offset': {'x': 5, 'y': -105}, 'r_offset': {'x': 34, 'y': -213}}

'village.tif': {'g_offset': {'x': 10, 'y': -87}, 'r_offset': {'x': 24, 'y': -139}}

'workshop.tif': {'g_offset': {'x': 1, 'y': -94}, 'r_offset': {'x': -10, 'y': -196}}/p>

Success Pictures

Wow these are even more gorgeous pictures, especially considering their age!

Problem Pictures

When using the cross correlation for the pixel value instead of the sum of squared distances, the accuracy of Cathedral and Emir were still poor. Village was a little bit blurry but everything else is great.

Selected Pictures

Offsets for green and red

'00156u.tif': {'g_offset': {'x': -5, 'y': -88}, 'r_offset': {'x': -16, 'y': -170}}

'00608u.tif': {'g_offset': {'x': 25, 'y': -96}, 'r_offset': {'x': 36, 'y': -185}}

'01001u.tif': {'g_offset': {'x': 10, 'y': -118}, 'r_offset': {'x': 18, 'y': -221}}

'01498u.tif': {'g_offset': {'x': 25, 'y': -96}, 'r_offset': {'x': -248, 'y': -131}}

'01772u.tif': {'g_offset': {'x': 18, 'y': -80}, 'r_offset': {'x': 27, 'y': -151}}

Success Pictures

Welp these are all pretty beautiful. I don't know what else to say.

Problem Pictures

Look at this poor fish picture. I think it is too homogenous of a picture for this method to be very accurate, so I think an edge detector would provide better results. There is simply not enough contrast between the different pixels of wall behind the fish.