4

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.

M.R.
  • 31,425
  • 8
  • 90
  • 281
  • 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] – flinty Jun 02 '20 at 16:29
  • @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. – M.R. Jun 02 '20 at 19:38
  • 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. – bill s Jun 02 '20 at 22:32
  • Doesn’t need to be random, just replace RandomImage with ResourceFunction[“RandomPhoto”] – user5601 Jun 03 '20 at 00:02
  • Correct @user5601 – M.R. Jun 03 '20 at 01:56
  • @M.R. Since it doesn't have to be random, and since there is reason to believe that having a non-random background will make the problem easier, please provide an example of that in the question. – C. E. Jun 03 '20 at 07:18
  • @C.E. Ok, just updated the question – M.R. Jun 03 '20 at 16:55
  • 1
    You see the issue right? The "extra" part of the image confuses ImageAlign... We're looking to align some subregion of image, which is an additional breakdance on top of it all! – M.R. Jun 03 '20 at 17:03
  • 2
    Perhaps a deep learning approach to image registration can be adapted to this? Will try to give this a go later during the week, if I find time - but figured I'd send two examples of supervised and unsupervised learning along. – George Varnavides Jul 13 '21 at 15:26

0 Answers0