CS180 Project 1: Colorizing the Prokudin-Gorskii Photo Collection
Author: Nicolas Rault-Wang (nraultwang at berkeley.edu)
Introduction
- The Prokudin-Gorskii collection consists of blue, green, and red negatives of a subject. For example, we have a triple negative of Emir at right.
- In this project, we have created a program to automatically produce colorized photos from the triple-negatives in the Prokudin-Gorskii collection.
- Our procedure has 3-steps, explained further in the following sections.
- Extract the individual color channels from the original triple negative.
- Align the structures in these negatives to form a coherent colorized photo.
- Automatically trim border artifacts from these aligned images.
Colorization Procedure
Step 1: Extracting Color Channel Negatives
- We begin by extracting the blue, red, and green channels from the original triple-negative photo.
- Each color channel has approximately the same dimensions, so we simply divide the original image into three equally-sized images, vertically padding if the height is not divisible by 3.
- The rightmost image shows the output of this step.
Step 2: Multi-resolution Color Alignment
Problem Description
- The pixels in the negatives extracted in Step 1 are not necessarily aligned because there are generally variations in their positions and the border widths between them.
- Aligning the negatives is equivalent to finding an displacement for channel so that every pixel position in each negative corresponds to the same structure.
- My alignment algorithm uses an image pyramid to efficiently compute these offsets:
- The algorithm takes two grayscale color negatives and of the same shape, then recursively computes the displacement vector that maximizes the objective . (NCCS is defined below.)
- To visualize this procedure, the surrounding figures show the optimal alignments at each level of the image pyramid
Alignment Algorithm
- Set and , where is the downsampling factor and is the maximum displacement in or .
- For , downsample each of and by to obtain and , respectively.
- If the largest dimension of exceeds 64, make a recursive call on and with resolution and search radius .
- This recursive call will return a displacement vector such that and are well aligned.
- Note that has twice the dimensions of , we have that and are approximately well aligned.
- Next, exhaustively examine all displacements to find the vector that best aligns and :
- Finally, return the displacement vector .
Defining NCCS
- NCCS: the Normalized Cross-Correlation between two Scharr-filtered, center-cropped grayscale images with the same shape.
Motivation for each feature of this metric:
- NCC: Since different channels have different baselines, it is a good idea to normalize before comparing them. Further, we’d like to ensure the structures between color channels are at the same pixel positions, and maximizing cross-correlation is a good way to do this.
- Edge detection: Most borders of an object should be present in all colors, so we can align the structures in different color channels by aligning their edges. Edge detection filters like Scharr create sparse patterns in each color channel that have large NCC scores when they are properly aligned. This NCC score rapidly falls off when the images are not well aligned, so filtering our color channels with an edge detector is a good way to help of our alignment procedure converge on a truly optimal displacement vector.
- Center-cropping: In my experiments, I found that it’s a lot easier to remove the image borders after alignment, so all the borders are still present during the alignment procedure. Since my metric relies on matching the edge-detections between color channels and the border-image transition is very sharp, my algorithm would often find strange alignments that tended to maximize the border-edge alignments between color channels, resulting in improperly aligned channels. A simple solution to this problem was excluding the edges from the metric calculations with a center crop.
- Notation
- : grayscale image.
- : center-cropped .
- : Scharr edge detection.
Step 3: Automatic Border Trimming
Problem Description
- Using our alignment algorithm, we can create properly-aligned, full-color images (see left, above). Next, we’d like to remove the remaining rectangular black and white borders around these colorized photos (see right, above). In this section we present our method for automatically cropping these borders.
Overview of Solution
- To crop the borders, we find the pixel-coordinates of a rectangle that, for each color channel, contains most, if not all, of the non-border pixels while excluding the majority of the border pixels. After finding these coordinates, we crop out the interior of the rectangle (see right, above). We’ll call these rectangles “cropping rectangles” in the following discussion.
- Since the border pixels are mostly very dark or very bright, we can use an edge detector such as the Canny edge detector to find the transitions between border-region pixels and non-border-region pixels.
- One complication is that the borders for each color channel are slightly different, resulting in slightly different cropping rectangles for every color channel. In my experimentation, I found that cropping the colorized photo with the average of these rectangles works for most images. Though there are some cases where the average rectangle also removes a small portion of the image in addition to the border.
- Since the border pixels are mostly very dark or very bright, we can use an edge detector such as the Canny edge detector to find the transitions between border-region pixels and non-border-region pixels.
Cropping Rectangle Algorithm
- Given an aligned negative from Step 2 with dimensions , create the following slices of the borders of .
- Top border:
I[:M/10, :]
- Bottom border:
I[9M/10:, :]
- Left border:
I[:, :N/10]
- Right border:
I[:, 9N/10:]
- Top border:
- Apply the Canny edge detector with to each of these slices.
- Compute the median and standard deviation of the distribution of edge-detection activations.
- Threshold the edge detections by setting any detection with Z-score less than 2 to 0.
- Find the column and row indices with the largest above-threshold activations, thus obtaining the top left and bottom right coordinates of the cropping rectangle.
N-pass Border-Trimming Algorithm
- Obtain the aligned color channels from Step 2: Multi-resolution Color Alignment.
- Run the Cropping Rectangle Algorithm on the three color channels, thus obtaining three cropping rectangles.
- Compute the average cropping rectangle by averaging the top left and bottom right pixel coordinates of these rectangles.
- Center crop the colorized photo to the average cropping rectangle.
- Repeat 2-4, feeding the output of 4 into 2, until a total of passes have been completed.
- The figures below show the cropping procedure with passes applied to the train.tif photo.
Comparisons: Before and After Applying 2-pass Border-Trimming
Results of 3-step Colorizing Procedure
Colorized Photos
Optimal Alignment Vectors
offset_vectors for emir.tif:
r: [ 40 106]
g: [24 48]
b: [0 0]
offset_vectors for monastery.jpg:
r: [2 2]
g: [ 2 -4]
b: [0 0]
offset_vectors for church.tif:
r: [-4 58]
g: [ 4 24]
b: [0 0]
offset_vectors for three_generations.tif:
r: [ 10 110]
g: [13 52]
b: [0 0]
offset_vectors for melons.tif:
r: [ 13 177]
g: [10 81]
b: [0 0]
offset_vectors for onion_church.tif:
r: [ 36 108]
g: [27 50]
b: [0 0]
offset_vectors for train.tif:
r: [32 86]
g: [ 7 42]
b: [0 0]
offset_vectors for tobolsk.jpg:
r: [3 6]
g: [2 2]
b: [0 0]
offset_vectors for icon.tif:
r: [22 90]
g: [18 41]
b: [0 0]
offset_vectors for cathedral.jpg:
r: [ 3 12]
g: [2 4]
b: [0 0]
offset_vectors for self_portrait.tif:
r: [ 37 175]
g: [29 78]
b: [0 0]
offset_vectors for harvesters.tif:
r: [ 14 123]
g: [18 60]
b: [0 0]
offset_vectors for sculpture.tif:
r: [-28 140]
g: [-12 33]
b: [0 0]
offset_vectors for lady.tif:
r: [ 12 115]
g: [ 8 54]
b: [0 0]
Credit to Notion for this template.