Overview
This project aims to us image processing techniques to automatic align the digitized Prokudin-Gorskii glass plate images. For this alignment, I first apply the recommended SSD based alignment to align the single-scale image. Then, I adapt it to large-scales by using multiscale pyramid. For the Bells and Whistles, I apply three new algorithms: (1) I use the edge features to do the alignment rather than the raw image; (2) I apply auto-cropping to the aligned images; (3) I propose a new alignment algorithm based on histograms.All the code is in the
How to run the code
1. select and change the image name index (0~9);
2. find the region for each question and uncomment those part;
3. run the code by python3 main_hw1.py.
Q1: Single-scale Image
I use SSD as the metric to do the alignment. I select the central 90% of the whole image to do the alignment to avoid the impact of the borders. See function
Results
Q2: Multi-Scale TIF images
For the large TIF images, I use the recommended pyramid version. I first rescale the image half and half until the whole pixel is smaller than 256 X 256. Then I find the offset (x,y) in the initial resolution. Next, I iteratively upsample the image and search the space [2x-3~2x+3, 2y-3~2y+3] to find the best offset in the next resolution until scale index is set to 1. During the experiments, the initial images are rescale to 1/16 of the original images.
See function align_tif(a,b,scale) and align_with_scale(a,b,x_min, x_max, y_min, y_max, scale) for details.
Results on the provided images:
emir.tif
harvesters.tif
icon.tif
lady.tif
self_portrait.tif
three_generations.tif
train.tif
turkmen.tif
village.tif
Results on extra images:
I downloaded 3 other tif images from the given collections. The results are shown below.
00800-00893a.tif
00900-00907a.tif
01000-01037a.tif
Q3: Bells and Whistles
I add 3 additional applications based on previous algorithm.
3.1 Alignment with extracted features.
Alignment with raw images is not robust. We could first do some feature extraction for the raw images and then align with the processed images. Here I use some filters to extract the features and realign with those processed images. I provided two kinds of filters: option 1 for sobel filters and option2 for roberts filters. I list two results for each filter in this part.
See function align_filters(a,b,scale,option) for details.
Results
emir.tif
icon.tif
3.2 Alignment with histograms.
Insipred by the histogram technique, I thought about a new algorithm to do the alignment. That is, the overall pixel distribution of each row and column of the image can represent the features. If we first calculate the mean pixel value of each raw and column, then we align with these mean value, we can get good result and save the time at the same time. So I write a function to first calculate the mean pixel value of each raw and column of two channels, then I use correalation to find the offset of the two channels.
Using this algorithm, we can get the aligned results in 2 seconds, which is much faster than the original algorithm. Again I showed two results here.
See function align_histogram(a,b) for details.
Results
icon.tif
self_portrait.tif
3.3 Auto-cropping.
By observing the original images, I found all the digitized images has a black boundary + a white boundary for each channel. So to do the auto-crop, I designed a 2-step method: first remove the white boundary then remove the black. I achieve that also by calculating the mean pixel values. If the mean pixel value is smaller than 0.15, I treat it as the part of black boundary, if larger than 0.85, I treat it as the white boundary. I calculate the boundary with the aligned image and do it with r,g,b channels invidually. I treat the overall tightest boundary from the three channels as the final boundary.
I showed two results here.
See function def autocrop(image, thres1, thres2) for details.