194-26 Project 1

Emily Chang cs194-26-aeu

Project Overview

This project focuses on using glass plate images and producing colored images. The way to achieve is this by layering the color channel images on top of one another so that they collectively make up one RGB image. The challenge was that the images were not aligned perfectly so each color channel image had to be offset before layering.

Approach

My approach was to align two images at a time, so I first aligned G to B, and then R to B. I computed the offset of the image by trying all displacements from -5 to 5 with step size 1 both horizontally and vertically. I then cropped the image so that only the middle section would be assessed because the noise in the borders would skew our score. The way I approached this was by removing 1/3 of the image from all sides. I computed the total score of the displacement using SSD. The displacement with the best score was used for image alignment, and we aligned both the red to blue and the green to blue. One problem was that this wasn't scalable, so for larger photos, this approach was too slow.

To address this issue, I used an image pyramid. The idea was to square root the size of the image continuously until the area of the image was less than 10,000. From there, I would start from the image with the smallest size, and compute a rough estimate of where we think the displacement should be. With that starting displacement, I then moved to the next smallest image, and with the previous displacement, I measured the offsets within 5 pixels left, right, up, and down. I computed the total score using SSD as before, and applied the displacement which had the best score to the next level of the pyramid.

Problems

Most images worked well with the algorithm I implemented. However, for images where the channel images do not have the same brightness values, this approach did not work and the final image looks like this:

To resolve this, I used a Canny edge detector which outlined the edges of the image, so that the brightness would no longer factor into our decision. The edge detector resulted in an image like this:

This way, we were able to align the images by focusing on the edges of each image channel and produce a much cleaner result:

Example Images

cathedral.jpg

offset: r: [3, 12] b: [2, 5]

emir.tif

offset: r: [41, 107] b: [24, 49]

harvesters.tif

offset: r: [15, 123] b:[17, 59]

icon.tif

offset: r: [23, 90] b: [18, 41]

lady.tif

offset: r: [11, 114] b:[8, 53]

monastery.jpg

offset: r: [2, 3] b:[2, -3]

nativity.jpg

offset: r: [0, 8] b:[1, 3]

settlers.jpg

offset: r: [-1, 15] b: [0, 7]

self_portrait.tif

offset: r: [37, 175] b:[29, 78]

three_generations.tif

offset: r: [11, 110] b: [14, 51]

train.tif

offset: r:[33, 86] b:[7, 43]

turkmen.tif

offset: r:[29, 117] b:[22, 56]

village.tif

offset: r: [22, 137] b: [12, 64]

Bells and whistles

Edge Detection

I implemented edge detection with a Canny edge detector. This particularly helped with aligning emir.tif. Edge detection for alignment is especially useful when the image channels have differing brightness values, which significantly skews the way we score each offset when we are computing the optimal displacement.

Automatic Cropping

Automatic cropping was achieved by using a Canny edge detector to first find all edges in the image. Then, I used Hough Line Transform to help me find all the lines from our edges. I then filtered out the lines by only considering lines within 10% of the border, so that I would not use lines which are actually part of the image. Of these possible lines, I chose the lines on each side (top, bottom, left, right) which was farthest away from the border.

Contrast

Contrast was achieved by equalizing the pixel intensity histogram, which allows us to distribute the intensity of an image more evenly. This feature is beneficial, as it helps improve the quality of images with low contrast.

Before/After Cropping and Contrast

Extra Examples

offset: r: [30, 90] b: [17, 18]

offset: r: [55, 141] b: [36, 64]

offset: r: [35, 154] b: [22, 74]