CS 194-26: Project 1

By Ana Cismaru

General Preprocessing

All images were converted to double, split into thirds for each color channel, and cropped by 5% in the x and y axis to remove black borders.

Simple Alignment

Simple alignment was applied to smaller jpg images. The process involved shifting each color image in both the x and y dimension with a range of [-15, 15]. For each image shift, a metric was calculated to determine whether the shift was more accurate than the current best image alignment. The metrics used in this project were the minimum of the Sum of Squared Differences (SSD) and the maximum of the Normalized Cross-Correlation (NCC). I ran the alignment procedure using both metrics and trying all 3 color options as the reference frame, and found that NCC aligned based on the green channel tends to yield better results.

cathedral.jpg aligned using NCC along red: G = (-1,-7), B = (-1,0)
cathedral.jpg aligned using NCC along green: R = (1,7), B = (-2,-5)
cathedral.jpg aligned using NCC along blue: R = (1,0), G = (2,5)
monastery.jpg aligned using NCC along red: G = (-1,-6), B = (-2,-3)
monastery.jpg aligned using NCC along green: R = (1,6), B = (-2,3)
monastery.jpg aligned using NCC along blue: R = (2,3), G = (2,-3)
tobolsk.jpg aligned using NCC along red: G = (-1,-4), B = (-3,-6)
tobolsk.jpg aligned using NCC along green: R = (1,4), B = (-3,-3)
tobolsk.jpg aligned using NCC along blue: R = (3,6), G = (3,3)
piony.jpg (additional) aligned using NCC along red: G = (1,-3), B = (0,-6)
piony.jpg (additional) aligned using NCC along green: R = (0,6), B = (0,3)
piony.jpg (additional) aligned using NCC along blue: R = (-1,3), G = (0,-3)

The complex alignment procedure was applied to the larger .tif images. Pyramid search consists of using a recursive strategy to align an image at a lower resolution using the simple alignment algorithm and then applying those offsets to the image at its original resolution. For my method, I scaled the image down by half and then by a quarter. When using an image with a factor of 4, the offset span of the simple alignment method was [-15,15], for a factor of 2 it was [-10, 10], and finally a span of [-3, 3] was applied on the original image. Since it was demonstrated that ncc works as a better method for simple alignment, I only ran the pyramid search using the ncc metric. I did still run it using all 3 color options as frames of reference and found that again, aligning based off green results in the cleanest images.

church.tif aligned using NCC along green: R = (-2,33), B = (0, -23)
emir.tif aligned using NCC along green: R = (17,55), B = (-23, -47)
harvesters.tif aligned using NCC along green: R = (-3,65), B = (-17, -59)
icon.tif aligned using NCC along green: R = (5,48), B = (-17, -41)
lady.tif aligned using NCC along green: R = (4,62), B = (-8, -53)
melons.tif aligned using NCC along green: R = (2,96), B = (-8, -83)
onion_church.tif aligned using NCC along green: R = (11,56), B = (-25, -52)
self_portrait.tif aligned using NCC along green: R = (7,97), B = (-26, -78)
three_generations.tif aligned using NCC along green: R = (-1,59), B = (-10, -53)
train.tif aligned using NCC along green: R = (26,44), B = (-4, -44)
workshop.tif aligned using NCC along green: R = (-11,52), B = (0, -53)
khan.tif (additional) aligned using NCC along green: R = (49,77), B = (-73, -42)

Bells and Whistles: Canny Edge Detection

To try to improve the alignment results, I implemented an alignment procedure that utilizes the Canny Edge Detector algorithm which is used to extract edges in an image. My procedure now consisted of calculating the upper and lower bounds of the Canny Edge detector for each color slide, applying the Canny Edge detection algorithm with the calculated bounds on each slide, and aligning the images using NCC based on the edges rather than the full picture. Once the edge offsets were calculated, they were applied to each original color slide and the color slides were stacked on top of each other. One interesting thing to note is that the best image to align against changes when using Canny edge detection compared to the previous method. Another thing we note is that we achieve the same offsets as when using the original image slides and NCC. This means that using Canny Edge detection is actually worse than using the color slides and NCC. This might be due to the complex nature of the image edges.

Edge Examples

Monastery Red Slide Edges
Monastery Green Slide Edges
Monastery Blue Slide Edges

Results

cathedral.jpg aligned using Canny along green: R = (1,7), B = (-2,-5)
cathedral.jpg aligned using NCC along green: R = (1,7), B = (-2,-5)
monastery.jpg aligned using Canny along blue: R = (2,3), G = (2,-3)
monastery.jpg aligned using NCC along blue: R = (2,3), G = (2,-3)
tobolsk.jpg aligned using Canny along red: G = (-1-43), B = (-3,-6)
tobolsk.jpg aligned using NCC along red: G = (-1-43), B = (-3,-6)
piony.jpg (additional) aligned using Canny along red: G = (-1,-3), B = (0,-6)
piony.jpg (additional) aligned using NCC along red: G = (-1,-3), B = (0,-6)

Bells and Whistles: Adaptive Histogram Equalization

Another method I used to improve results is was the Adaptive Histogram Equalization method. This method functions by distributing the pixel intensities such that the cdf of the pixel intensity's histogram is 1. We can apply the histogram equalization method after performing our pyramid search alignment method to help equalize our constrasts even further. We can see in the results that the equalized images tend to have darker bright colors and lighter dark colors, making the image more natural seeming.

Results

emir.tif with histogram equalization
emir.tif aligned using NCC along green: R = (17,55), B = (-23, -47)
lady.tif with histogram equalization
lady.tif aligned using NCC along green: R = (4,62), B = (-8, -53)
harvesters.tif with histogram equalization
harvesters.tif aligned using NCC along green: R = (-3,65), B = (-17, -59)
workshop.tif with histogram equalization
workshop.tif aligned using NCC along green: R = (-11,52), B = (0, -53)