Skip to main content

correlation - How to align images?


I have two grayscale images (img1, img2) which contain objects seen with two cameras. Some objects are the same (not same shape and intensity) and are seen in both images. Some objects are only seen in img1 or img2.


I would like to align the images in such a way that the objects seen in both images are overlapping.


How can I determine the vertical and horizontal shift between the two images?


Here are the images:



img1:


enter image description here


img2:


enter image description here


What I tried:


pts = ImageCorrespondingPoints[img1, img2, KeypointStrength -> 0.0002]

{{{34.6035, 72.9785}}, {{48.1733, 82.9132}}}

xshift = Mean[pts[[All, All, 1]][[2]] - pts[[All, All, 1]][[1]]]


13.5698

yshift = Mean[pts[[All, All, 2]][[2]] - pts[[All, All, 2]][[1]]]

9.93468

This seems to be correct. When I look only at the vertically elongated object in the center of img2 then I find manually roughly: xshift=10, yshift=13.


What confuses me:


The found points pts do not correspond to img1 or img2:



HighlightImage[img1, pts]

enter image description here


HighlightImage[img2, pts]

enter image description here


Where is the error in HighlightImage?


Can ImageCorrelate or ImageAlign be used to find the shift or do you have another solution?



Answer



My solution is the following:



Determine the shift between both images:


{merit, trans} = 
FindGeometricTransform[img2, img1,
TransformationClass -> "Translation"];


enter image description here



Applying the shifts


imgt = ImageTransformation[img2, trans, DataRange -> Full]


Combine images


Blend[{ColorNegate[img1], imgt}, {0.8, 0.2}]


enter image description here



Comments