In this project we needed to overlay 3 black and white negatives in order ot produce a single full color RGB image.
Splitting this trifold of black and white negatives isn't perfect, however. We need to create an algorithm to align them so they look right once overlayed.
We choose one channel to remain stationary. For the other two channels, we try shifting the 2D matrix through a specified window for its x and y coordinates. At each x and y coordinate shift, we calculate the normalized cross correlation value. The highest NCC value will dictate which shift is best for the channel. Note: When calculating NCCs, we crop all the images by 10% on each side to make it less likely that we're comparing borders instead of the actual image.
For large enough images, this search becomes too expensive. We now implement an image pyramid where the window search is only performed once the image is sufficiently small, achieved by recursively scaling down the image by half until a specified image size is reached. This shift is then propagated and scaled up to give us the shift we need on our original, large pixel-ed image.
All images use blue for the base channel.
An offset (x,y) means the origin of the channel was shifted (and excess pixels rolled) x pixels down, y pixels right
Image: Cathedral
Offsets: Green (5,2) Red (12,3)
Image: Emir
Offsets: Green (48,32) Red (96,-208)
Image: Harvesters
Offsets: Green (64,16) Red (128,16)
Image: Icon
Offsets: Green (48,16) Red (96,16)
Image: Lady
Offsets: Green (48,16) Red (112,16)
Image: Monastery
Offsets: Green (-3,2) Red (3,2)
Image: Nativity
Offsets: Green (3,1) Red (7,0)
Image: Self-Portrait
Offsets: Green (80,32) Red (176,32)
Image: Settlers
Offsets: Green (7,0) Red (14,-1)
Image: Three Generations
Offsets: Green (48,16) Red (112,16)
Image: Train
Offsets: Green (48,0) Red (96,32)
Image: Turkment
Offsets: Green (48,16) Red (112,32)
Image: Village
Offsets: Green (64,16) Red (128,16)
Image: Bridge Over River
Offsets: Green (32,0) Red (144,0)
Image: Piony
Offsets: Green (48,0) Red (112,0)
Image: Lugano
Offsets: Green (48,0) Red (112,32)
Emir alignment didn't turn out very good. My guess is that the blue channel values were very high, and the red channel values very low, so all alignments had bad NCC scores and the optimal alignment was indistinguishable from the worse alignments.