Hello,
I am trying to co-register two very simple 2D png images of rectangles (white rectangle value 256 on black (0 value) background), but struggling with getting them aligned no matter what metric, optimizer or parameters I choose. Would anybody please be so kind and review the code below and give me a hint about what might be wrong with this code/parameters, etc…?
Thanks a lot!!
Images are attached.
Welcome to the world of image registration! You have successfully created a corner case as your initial input. Happens to the best of us.
TL;DR
Convert your binary (i>0 or i==255 whichever way you want to binarize them) images to distance maps and register those using the mean squares similarity metric and basic registration settings, no need for any advanced settings and it will work:
An image is a dense regular grid sampling of a continuous signal. When the original signal occupies a small region in the image, using intensity based registration to align the two images is likely to fail.
This is particularly an issue when the intensity values in the object do not vary (two contours with single intensity value). In such cases the image-to-image registration is actually a less appropriate approach than a contour-to-contour / surface-to-surface registration. So when you have an image representation of a contour/surface you can:
Extract the contour/surface and perform registration using classics such as the Iterative Closest Point algorithm (available in ITK, not in SimpleITK).
Convert the sparse representation to a distance map as done above and solve it using intensity based registration.
As this appears to be your initial foray into registration, I highly recommend skimming the SimpleITK notebooks repository, specifically the 6* series which deal with registration and illustrate various aspects of the task and how to address them. Specifically, go over the registration initialization and the registration errors, notebooks. The concepts described there are general and will serve you well no matter what tool you use for registration.
For a concise overview of the toolkit see the tutorial.
Yes exactly. Graphic the metric value over points and the effects of performing gaussian smoothing on on or two of this images is a enlightening exercise.