Part 1, single Scale alignment, using SAD

function implementing single scale alignment

Applying single scale function to small scale image

ZNCC alignment result

We can also pass another simple metric, the zero normalized cross correlation for the entire image

On this small image, the single scale search found an answer quickly

Larger images, requires multiscale

Implementation of multiscale, course to fine alignment with recursion

Function takes in two images of the same size. If the images are small enough, it searches for an alignment. If images are too large, it first searches for an alignment on a downscaled version, before searching for an alignment at full scale

ZNCC has basically the same result on this image

Alignment turned out well on this image! There is a small difference between SAD and ZNCC, but I don't see the difference in the resulting image

However, there is still a lot of border, which we can now try to crop out

Cropping using dark to light edge detection

Crop isn't tight. Could likely be improved further.

imperfect alignment, but good crop

Alignment looks very good, crop is tight on most sides, but a dark to white edge fooled the detector

Aligment looks good on some parts of the image, but it seems like pure translation may not be able to solve this one. Cropping is tight on all sides.

Alignment using Gradient Descent in Pytorch

The section below uses pytorch to set up a gradient descent search over scale and translation. Scale and translation are passed in through an affine transform, which is full differentiable. When updating the affine transform, I discarded parts of the gradient that would change parameters other than scale and translation. One enhancement, to improve the size of the local cost basin was to smooth the reference image.

Alignment was pretty successful! This didn't work for all images

Full Results

For completeness, here is the multi scale alignment for the full set