# Project 1: Color Alignment (Writeup)

## Brief

The implementation chosen is a relatively straightforward one and will be discussed in the subsequent sections. The images are aligned via a pyramid scheme as specified, at each level of the pyramid edges are derived using a Canny edge detector via the Matlab function edge(a,'canny').

• Automatic margin removal
• Automatic White balancing
• Automatic contrast
More details on these will be presented in the section Graduate Credit

## Algorithm Description

The function imalign(a,b,thresh) returns alignment offsets for image b with respect to image a. The parameter thresh provides a threshold such that the image pyramid will end when the number of pixels on any edge drops below thresh.

The imalign() function is a recursive function. In the recursive case we reduce the image by a set scale ( 1/2 seems to work well ) and then call imalign(a_half, b_half, thresh). When the number of pixels in an edge drops below thresh we compute the offsets and return.

To compute the offsets I first compute edges for each of the input images. Edges are computed at each scale of the pyramid. The input images are then translated with respect to each other up to a maximum distance ( 7 pixels works well ). The element-wise logical AND is computed between each image and the total score is summed. The objective function is thus,

```  obj = sum( sum( A_edges & B_edges ) );
```

The translation with the highest score is returned. In the recursive case the offset retrieved at level k-1 is doubled and the process is repeated at level k.

Regarding single-scale and multiscale implementations; the function imalign() takes the threshold for which to cut off the pyramid. By setting this threshold to the size of the maximum edge in the image we retrieve a single-scale implementation.

The following improvements were implemented for graduate credit.

### Automatic White Balancing

 Before White Balance After White Balance

A simple approach to white balancing was selected. For each channel we compute the average intensity of the image. Using the gray world assumption we then compute the difference between this average and 0.5. This delta is added to the intensity of each pixel in the image.

### Automatic Contrast

We use another simple approach here to automatically adjust contrast. We compute the Michelson contrast ratio, namely (I_max - I_min)/(I_max + I_min). We then scale each pixel by this ratio to adjust the contrast.

### Automatic Margin Removal

A couple of techniques were used to remove margins. The simplest was to deterministically remove 10% of the image on each edge. This worked well actually, but is not the most elegant technique.

A more elegant approach was implemented. Namely, an edge detector is run on the image and then we compute the vertical and horizontal sums. For some maximum offset (again 10%) we find the maximum horizontal and vertical edges. We then retain the image enclosed by these maximum edges. The drawback to this technique is that sometimes multiple edges appear in the margins and sometimes not all of the margin is removed.

## Results

The results a provided below and have been scaled down to 300px wide. You may click on each of them to view the full-size image.

One image was particularly bad and is denoted as such with a caption. It is believed that this image has poor alignment due to the technique used. This image displays many edges due to the logs of the cabin. Because of this and because edges are used to align there is probably a solution that maximizes the specified objective by lining up different edges of the logs.

 Note: The above result is the worst one. See comments above