The goal of this project is to automatically generate a color image with image processing techniques according to the methods designed by Prokudin-Gorskii. The Python programming language is used.
Basically, there are three photos of the exact same scene. Each has a different colored filter (Seen below). The main idea is to align the R, G, B layer images to get the final color image and the filter order from top to bottom is BGR. The two recommended metrics are SSD and NCC.
The SSD is used in this project. First, the input image is divided into three images of the same size. Then the image is cropped by 5% in the x direction while 2% in the y direction. The B layer works as the pivot. By exhaustively searching over a window of possible displacements, the displacement with the lowest SSD is used as the final displacement for R and G layer.
First, we processed the JPG formate image. As mentioned in the methodology, I divided the input image and cropped it. I then rolled the image and the range of search is [-15,15] in both the x and y direction. Then I choose the displacement with the lowest SSD value. Finally, I applied that displacement vector to the original image and stack three channel images.
                           While this method works well for the JPG images with small sizes, this method is not suitable for TIF format pictures with much bigger sizes. I use the image pyramid to speed up the image proesssing.
To process TIF images in a short time, the Image Pyramid method is introduced. An image pyramid represents the image at multiple scales with a factor of 2 in this project. The processing is done sequentially starting from the smallest image and going down the pyramid to the original images by recursion. The number of layer is set as 6 (From 5th layer to the 0th layer).
In order to further reduce processing time, we set different range of search in the different layer. The range of research in the smallest image is [-15, 15] while that for the original image is [-3, 3]. In the middle layer, the range is set as the [-10, 10]. The runtime is reduced to less than one minute. For this project, the range in the toppest layer could set as [-1,1] to further reduce runtime. But in order to imrpove generalization, I keep it as [-3, 3].
                           We could see that the image pyramid has a good performance except for the case of the Emir of Bukhar. It is because different color channels of this image do not actually have the same brightness values. So, new features need to be introduced to process this case.
I built the image gradient function with the Prewitt operator referring to Wikipedia [1]. The raw pixels matrix were convolved with the two 3×3 kernels and then we calculated the squre root of the sum of square of the matrix to get final feature matrix. I still used the SSD as the metric.
                         1. Better Features: Although I impletmented the self-defined image gradient function, it took much time to finish convolution. I used the OpenCV Sobel operator [2] and it reduced time to less than one minute. The reulst is listed above and the displacement is the same with the result from the self-defined function.
2. Automatic Contrasting: Due to the sunlight, the top of the shed is well lit, causing the light to be overexposed. The lack of light under the shed makes it difficult to see the person and fruits.
Firstly, I followed the formula: (Matrix - Matrix_min) / (Matrix_max - Matrix_min) to rescale the image.
Then, I used Python Imaging Library (PIL) to automatically adjust image contrast.[4]. This function calculates a histogram of the input image, removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255). After processing, the image looks more colorful and the items under the shed looks more clear.
                     3. Automatic White Balance: Although the lady image shows a good alignment, its color looks not natural. Take the white blouse as an example. This white blouse looks red. So, I used the OpenCV to automatically adjust it [3]. After processing, it looks better. The white blouse becomes more white.
                     4. Automatic cropping: Because the original boundary is black, this is designed to remove the black borders. We removed the line with more than 0.75 pixel values more than 0.9. From the below image, without cropping, result is very bad. By automatically cropping, the image (size: 341 X 391) is cropped 10, 9, 8 and 6 on left, right, upper and lower boundary.
                   5. Aligning and processing data from other sources: I chose extra images randomly to process [5]. Becuase TIF image is more difficult to proecss, I choose two TIF images and one JPG images. It also has good pderformance on other images.