Images of the Russian Empire: Colorizing the Prokudin-Gorskii photo collection

Emir, in all his glory

Overview

Early in 1900's a Russian photographer, Sergei Mikhailovich Prokudin-Gorskii, attempted to make color photos by taking three exposures through red, green and blue filters stacked one ontop of another. The goal of this project is to create a procedure to automatically align each of these images to create a single color image with as little errors in alignment as possible.

Basic Alignment

The most straightforward way to align these images is to have some heuristic, and take the best score from all possible ways to overlay the channels. This is very slow, we can do better. Since the images are already mostly aligned we can search through a smaller displacement window and use the best score in that window. For the heuristic we can take the summed squared errors of every pixel value and the lower the score the better the displacement. Below are the results from this method.

A Cathedral Emir, only a fraction of his glory

Image Pyramid

For larger images the basic method is too slow, since the window we would need to search over can be hundreds of pixels. A better way would be to rescale the images and do the basic alignment on the downscaled image. This means if I rescaled an image down to 1/8th its original size, every pixel I cover will be 8 pixels in the original image. With this knowledge we can find the best displacement for each rescaled image, and propagate this displacment up our image pyramid to start the search from a more informed position. Not only does this greatly increase performance but it also greatly increases the quality of the image as shown below.

A Cathedral Emir, at some of his glory

Bells and Whistles

A Better Heuristic

Using the raw pixel values has a major downfall, what if a large portion of the image is either red, green, or blue? In the case of our friend Emir here, his clothes are mostly blue which means that we might have some problems attempting to align his picture. One solution is to do edge dectection on the image. Edge dectection finds the edges of objects in an image and outlines them. Using the edges of our subject we can much better align his body and the background to their true displacement. I used canny edge dectction, found in the skimage library, for simple and quick edge detection. While this did hurt performance, in the end it led to greatly increased picture quality.

A Cathedrals green channel edge detected Emirs green channel edge detected

Automatic Cropping

From all the examples from above the borders of our image dont particularly look very nice, in order to fix this I implemented automatic cropping. The basic idea is to use edge detection on the borders of an image (about the outer 10% of the image) and find straight lines along the edge and crop the image there. In order to find the best cropping I use several values to tweak the edge detection to be smoother or more granular, and I take the maximum ammount of cropping and use that in the final result.

Gallery

Emir in his full unthrottled glory
Runtime: 02:34.3
Displacement: G(23, 49) R(40, 107)
icon
Runtime: 03:04.1
Displacement: G(16, 38) R(22, 88)
lady
Runtime: 02:42.2
Displacement: G(10, 56) R(13, 120)
train
Runtime: 02:39.8
Displacement: G(2, 48) R(28, 84)
church
Runtime: 02:28.3
Displacement: G(4, 25) R(-4, 58)
melons
Runtime: 02:43.9
Displacement: G(9, 79) R(11, 182)
tobolsk
Runtime: 00:01.3
Displacement: G(2, 3) R(3 6)
cathedral
Runtime: 00:01.3
Displacement: G(2, 5) R(3, 12)
monastery
Runtime: 00:01.8
Displacement: G(2, -3) R(2, 3)
sculputre
Runtime: 02:39.4
Displacement: G(-11, 33) R(-27, 140)
harvesters
Runtime: 02:54.1
Displacement: G(18, 60) R(9, 123)
onion church
Runtime: 04:40.8
Displacement: G(24, 52) R(34, 107)
three generations
Runtime: 02:46.3
Displacement: G(11, 56) R(7, 111)
self portrait
Runtime: 03:00.9
Displacement: G(29, 77) R(37, 175)