Computer Vision, Fall 2015

Assignment 1


1.1 Bayer demosaicing

The individual color channels are separated. These can be reconstructed by using the following linear filters. Red/blue filter = 0.25 * [ 1, 2, 1; 2, 4, 2; 1, 2, 1;]; Green Filter= 0.25 * [ 0, 1, 0; 1, 4, 1; 0, 1, 0;]; These filters are convolved to get the reconstructed color channels. The filters can be constructed by merely observing the pattern of individual color channels. The method I followed was to find separate filters for 4-neighbors and 2-neighbors cases. After that, we can combine the filters by observing that these filters don't overlap.

Original Image
Mosaic image, RGGB sequence
Reconstructed Image


Heat map of difference
BadPatch

We have used linear interpolation to approximate the missing values. This does not hold true across edges. Hence, we observe bad coloring primarily around strong edges.
I used the circular padding for image borders. The program to get this results is a1_1.m run this file.
Mean absolute difference = 1.4833
Maximum absolute difference = 166

1.2 Image Alignment

Prokudin-Gorskii captured three photographs for R, G and B color channels by a set of three cameras displaced by some vertical offset. The aim of this assignment is to align these three image channels so that we get a good color image.

The program has fields for directory path and image filename. The function which does the alignment is alignImages. alignImages uses canny edge detection for finding edge-maps, normxcorr2 for finding the correlation and a window of [ -maxlag, +maxLag] in both X & Y directions to find the correct shifts. Function shiftImages shifts the channels using the above shifts.
Edit a1_2.m to define image name and directory and run it. a1_2.m sets up the inputs for alignImage by splitting the image into three vertical equal parts. I have used the red channel as reference as it performed the best in qualitative sense. Intuitively I thought green should perform the best since it is approximately in the middle, but this was not the case.

1.2.2 Bonus: Algorithm acceleration

For this, I have implemented a function called multiScaleAlign which requires the pyramid height called scaleMax. I downsample by factor of 2scaleMax, find the shifts and go to the higher( image is bigger) level. For fast alignment at higher levels, I consider only a part of the image which is the center region when it is divided into 9 parts. The intuition behind this follows from the rule of thirds from photography.
For even faster alignment, I have kept a hard limit for the size of the center image region, imMax * imMax . While going from coarsest level to higher levels, whenever center region size becomes bigger than imMax * imMax, I clip the center region into imMax* imMax size. This method although fast has an assumption, ie the center patch will not be a 'flat' region. Values used: imMax = 400;
maxlag = 40;
scaleMax = 4;
Edit a1_bonus.m to define path and image name and run it.

Matlab Files


a1_1.m
a1_2.m
alignImages function
shiftImages function
a1_bonus.m
multiScaleAlign function

Result Images

Colorized Image
Colorized Image
Colorized Image
Colorized Image
Colorized Image
Colorized Image

Hi-Res Result Images

Hi-Res colorized Image
Hi-Res colorized Image
Hi-Res colorized Image