3
$\begingroup$

ImageAlign[ref, i] works well when image i is fully contained within the reference image ref, but not so well when only a subregion of i appears in ref. For example:

r1 = ResourceFunction["RandomPhoto"][200];
r2 = ResourceFunction["RandomPhoto"][200];
i1 = ImageTake[r2, {120, 160}, {80, 180}];
i2 = ImageTake[r2, {90, 180}, {110, 140}];
ref = ImageCompose[r1, i1];
{ref, ImageAlign[ref, i2]}

enter image description here

How can I get ImageAlign to return the region at which they overlap:

ImageCompose[ref, {ImageApply[{.5, 1.5, .5}*# &, i2], .5}, {70, 70}]

enter image description here

I've tried using ImageCorrelate and ImageCorrespondingPoints but can't seem to get it quite right, but I'm sure there's an elegant solution here.

$\endgroup$
  • $\begingroup$ I get a black image for some reason but I think you'll need something like this: crsp = ImageCorrespondingPoints[h, ref]; transform = Last@FindGeometricTransform[crsp[[1]], crsp[[2]], TransformationClass -> "Translation"]; ImageTransformation[ref, transform] $\endgroup$ – flinty Jun 2 at 16:29
  • $\begingroup$ @flinty Yes, but what I want is to find the rectangle where i2 and ref could intersect if moved and scaled. So you're right I'd want to look at ImageCorrespondingPoints[ref, i2], but unfortunately that is empty. $\endgroup$ – M.R. Jun 2 at 19:38
  • $\begingroup$ Random images are hard because they have so many keypoints, all of low quality. If your image really is a natural image surrounded by noise, I would suggest croping the image, either manually or by algorithm, allowing imageAlign to do its thing. $\endgroup$ – bill s Jun 2 at 22:32
  • $\begingroup$ Doesn’t need to be random, just replace RandomImage with ResourceFunction[“RandomPhoto”] $\endgroup$ – user5601 Jun 3 at 0:02
  • $\begingroup$ Correct @user5601 $\endgroup$ – M.R. Jun 3 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.