[COMPSCI 180] Colorize the History
Jerry Xiao Two

Overview

This project focuses on colorizing historical black and white images by aligning three separate color channels (red, green, and blue) that were captured using different filters. The main challenge is that these channels are often misaligned due to camera movement between exposures, requiring precise alignment algorithms to reconstruct the original color image. I implemented a multi-scale pyramid alignment algorithm using normalized cross-correlation (NCC) as the similarity metric.

Approach

The approach works by:

  1. Image Preprocessing: Crop border (10% from each edge) to eliminate artifacts that could interfere with alignment
  2. Multi-scale Alignment: Build image pyramids to handle large displacements efficiently
  3. Normalized Cross-Correlation: Use NCC to find optimal alignment offsets between color channels
  4. Edge-based Alignment: Sobel edge detection followed by NCC on the edge maps to solve Emir case

Part 1: Start with the simple example

To start the project, I start with the simple smaller example monastry.jpg and cathedral.jpg. After cropping the image into three separate parts (b, g, r), each part has a size of around (341, 390). While we are suggested to use alignment to align three different channels, naively calculating the result will lead to this:

Cathedral Naive
Cathedral - Naive Result
Green shift: (1, -1), Red shift: (7, -1)
Time taken: 1.13 seconds
Monastery Naive
Monastery - Naive Result
Green shift: (-6, 0), Red shift: (9, 1)
Time taken: 1.15 seconds

We can see that the naive implementation is not good enough, the actual building is not aligned. Why is this happening? In the alignment process, I am using normalized cross-correlation to align the image. The normalized cross-correlation is a measure of the similarity between two images. The higher the normalized cross-correlation, the more similar the two images are. To find out the reason, I print out all the channels and we can see that there are borders along the edges of the image, and these borders contribute to the high normalized cross-correlation score.

Monastery Blue Naive
Monastery Blue Channel
Monastery Green Naive
Monastery Green Channel
Monastery Red Naive
Monastery Red Channel

Therefore, I choose to crop the image borders (each by 10% of the width and height) to get the following result:

Cathedral
Cathedral - Result
Green shift: (5, 2), Red shift: (12, 3)
Time taken: 0.82 seconds
Monastery
Monastery - Result
Green shift: (-3, 2), Red shift: (3, 2)
Time taken: 0.91 seconds

Part 2: Play with Image Pyramid

To cope with larger files, I implement the image pyramid to downsample the image. This is because the simple way of aligning the image is ofcomplexity for the search range. For a larger image, the search range will be larger, and the compute time will be intolerable.

By downsampling the image, we can first conduct a coarse alignment on the smaller image, upsample the image to the original size, and then conduct a finer alignment with smaller search range. This way, we can avoid the expensive computation of the large image.

ImageShapeRegular Time (s)Pyramid Time (s)SpeedupGreen Shift (Reg → Pyr)Red Shift (Reg → Pyr)
emir.tif2570×2963126.2414.138.94×(15, 15) → (49, 24)(15, -4) → (26, -829)
italil.tif2586×2978133.9610.3112.99×(15, 15) → (38, 21)(15, 15) → (76, 35)
church.tif2563×2909131.1121.516.09×(15, 4) → (25, 4)(15, -13) → (58, -4)
three_generations.tif2570×2973114.838.2613.90×(15, 12) → (53, 14)(15, 8) → (112, 11)
lugano.tif2597×3026110.249.0212.23×(15, -15) → (41, -16)(15, -15) → (92, -29)
melons.tif2594×3017103.437.8113.25×(15, 3) → (81, 10)(15, 10) → (178, 13)
lastochikino.tif2594×296199.847.5013.30×(-2, -2) → (-2, -2)(15, 0) → (75, -8)
icon.tif2597×299496.987.6512.68×(15, 15) → (41, 17)(0, 15) → (89, 23)
siren.tif2601×3056121.689.8812.32×(15, -7) → (49, -6)(15, -15) → (95, -25)
self_portrait.tif2602×3049127.4310.1112.60×(15, 15) → (78, 29)(15, 15) → (176, 37)
harvesters.tif2577×2948118.2010.0411.77×(15, 15) → (59, 16)(15, 6) → (124, 13)

We can see that if we use the naive implementation, most of the images will reach the shifting bound. However, with the image pyramid, the pictures are allowed to align with each other from a larger search range, thus leading to a much better result. The results from pyramid are here:

Emir Pyramid
Emir - Pyramid Result
Italil Pyramid
Italil - Pyramid Result
Church Pyramid
Church - Pyramid Result
Three Generations Pyramid
Three Generations - Pyramid Result
Lugano Pyramid
Lugano - Pyramid Result
Melons Pyramid
Melons - Pyramid Result
Lastochikino Pyramid
Lastochikino - Pyramid Result
Icon Pyramid
Icon - Pyramid Result
Siren Pyramid
Siren - Pyramid Result
Self Portrait Pyramid
Self Portrait - Pyramid Result
Harvesters Pyramid
Harvesters - Pyramid Result

It is really interesting though that one of the images produced by the pyramid has relatively large shift error, which is the emir.tif. As mentioned in the project description:

Note that in the case like the Emir of Bukhara (show on right), the images to be matched do not actually have the same brightness values (they > are different color channels), so you might have to use a cleverer metric, or different features than the raw pixels.

Therefore, I separately implement a different metric to align the image. I use the sobel kernel to extract the edges of the image, and then use the normalized cross-correlation to align the image. Here you can see the edges are much more aligned.

Emir First Channel
Emir First Channel
Emir Second Channel
Emir Second Channel
Emir Reference Channel
Emir Reference Channel
The result of the emir image is shown below:
Emir
Emir - Result
Green shift: (49, 23), Red shift: (106, 40)
Time taken: 8.15 seconds

Part 3: Self-selected Example

I have selected two more examples from the gallery, naming the house and the lake. And here are the results:

House
House - Result
Green shift: (26, 18), Red shift: (121, 35)
Time taken: 10.93 seconds
Lake
Lake - Result
Green shift: (-22, 8), Red shift: (-33, 10)
Time taken: 21.70 seonds
Powered by Hexo & Theme Keep
This site is deployed on