CS 294-26 Hw1: Images of the Russian Empire

By Gefen Kohavi

Project Overview

The main idea of this project is to align 3 different rgb channels to create one rgb image. The challenge lies in the fact that each chanell can have differences with other channels and can have large distortions in the image. The idea is to combine all three channels along with some shift for two channels so that the resulting image looks like a normal rgb image.

Approach

The initial approach follows a simple iteration over a window range of the image. The image is cropped to remove borders and other potential distortions that would affect alignment. Then the sobel operation is done as edges are important features to align as well as it ignores the different luminances of each channel. Next the best shift in a horizontal and vertical range from -15 to 15 is found by using the sum of square differences between the two channels. Once the shift is found, each channel is shifted to their corresponding amount and then each channel is stacked to make an image.

Next, for use on larger images, a image pyramid is constructed. This is an recursive process where it uses the previous approach on smaller and smaller scale images of itself (decreasing by a factor of 2 each time). First it recurses until it gets to some small, pre-specified image size of itself (200). Then it finds the large scale but coarse shift in that size. Then when the function goes back to a larger scale of itself it finds a more fine tuned shift and adds it to twice the shift of its recursive call. To make this more efficient, the window of shift ranges increases as the image get's smaller. This makes sense to do because ideally the larger images will only need to find fine grained shifts. There were no problems with any of the images. Small images take ~.15 seconds to align and lage images take ~7 seconds to align.

Example Images and Offsets

Contains 13 provided images with 3 extra images (at the end).

Here is the list of image names along with their red and green channel offsets.

Image name Green x-shift Green y-shift Red x-shift Red y-shift
cathedral.jpg 2 5 3 12
monastery.jpg 2 -3 2 3
nativity.jpg 1 3 0 8
settlers.jpg 0 7 -1 14
emir.tif 24 49 40 107
harvesters.tif 17 60 14 124
icon.tif 17 42 23 90
lady.tif 9 56 13 120
self_portrait.tif 29 78 37 176
three_generations.tif 12 54 9 111
train.tif 2 41 29 85
turkmen.tif 22 57 28 117
village.tiff 10 64 21 137
extra_house.jpg 1 2 1 7
extra_monument.jpg 1 1 2 3
extra_water.jpg 0 1 0 2

Bells and Whistles

White Balancing

The goal of white balancing is to make a neutral illuminant in an image. This is usually done by some estimation of the illuminant and a corresponding normalization of it to make a neutral looking image. My approach involves normalizing the a and b values in the lab color scheme.

Automatic Contrast

To improve contrast in images, the color histogram for RGB must take up the entire range 0-255. My approach to autocontrasting uses the top and bottom 5% of luminance in each image and stretch them to their corresponding shade, clipping values that go outside of the acceptable range for an image. Examples of some before and after images are shown below.

Chromatic Blur

One of the issues with this dataset of images is that there is some non-linear distortion between each channel, meaning that channels may be overlapping well in one part of the image but not well in another part. Another issue known with cameras is chromatic abberation, where the lens has a different refractive index for different wavelengths of light. This results in edge efects usually where edges of objects either have a magenta or greenish hue. This also could be a reason why the image doesn't seem aligned in some parts. To fix this problem, chroma blurring is used. The process first involves taking the current, aligned image and putting it in the LAB color scheme. Slight Gaussian Blurring is done in the a and b channels. After this, the image is converted back into RGB. The quality of images, for some fine grained detail, have improved as a result of this method. An example is shown below.

Here is a segment of one of the aligned images above. Notice the boundary effects.

Here are the results after chroma blur. While not completely gone, the boundary effects are reduced.

Here is a closer comparison.
Before
After

While the problems with boundary effects are improved, this post processing technique does make the image slightly more blurry (although not in the luminance channel).

Sobel Edge Operation

The sobel edge detector is one of the simplest edge detector algorithms. It operates by having two kernels that convolve over an image, giving approximations of the x and y gradients of an image (denoted Gx, Gy). Given the new gradient images, the new pixel values are defined as (Gx^2+Gy^2)^0.5 . In addition, I use skimage's erosion operator to denoise and remove small detected edges caused by noise. Here is an image of turkmen.jpg run through my definition of sobel. Running the the image pyramid on my definition of sobel results in similar images to skimage's version, however, there are a few picutres where it is 1 or 2 pixels off.