Aligning transformed images to form a mosaic

I'm trying to align and stitch together these images to form a mosaic:

It's a similar problem as this one:

How to keep the non-overlapping parts when aligning images?

However, (and I may not have properly understood that answer) I haven't been able to get that approach to work with these images. I want to get image 1 and all of a transformed image 2 nicely overlaid.

So to design a simpler test case, I created two images like this:

This is the result I'm trying to achieve (done here manually, with image borders added to highlight that the two images are whole but superimposed):

So I tried find the geometric transform, and then applying it:

i23 has the correct rotation and translation to nicely overlay i21, but how do I achieve the final overlaying of the images to get the desired result?

• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. – bbgodfrey May 7 '15 at 3:42
• Daryl - I don't have time to post a properly done answer, but just taking the example images and applying the code shown in the documentation for FindGeometricTransform works directly if the images are rotated -90 degrees .... so there's something in there I'd venture that specifies/limits the way matches are found/evaluated. I don't do much (if any) such image work, so can't offer much more, but perhaps that will spur ideas. – ciao May 9 '15 at 22:11
• I think FindGeometricTransform is finding the right transform of i20 to match it up with i21, and ImageTransformation is applying it properly to i20 to yield i23, but I don't know how to superimpose the transformed image i23 over the top of image i21 to yield the desired result shown manually stitched above. – DarylWM May 10 '15 at 1:24

Well I found a way to achieve my desired result. Taking the original images as i1 and i2, I reduced them to 658x370, just to keep them manageable.

In[3]:= ImageDimensions[i1][[1]]
Out[3]= 658

Out[4]= 329.

Out[5]= 185.


Then I padded the first image to make room for the second one to be added.

i1pad = ImagePad[i1, {{0, 0}, {0, ypad}}]


I used ImageAlign to find a transform that would align i2 with i1, and applied it to i2.

i2tr = ImageAlign[i1pad, i2, Method -> "Keypoints", TransformationClass -> "Rigid", Background -> Transparent]


Then I created an image by overlaying the transformed image on top of the padded i1.

ImageCompose[i1pad, i2tr]


That's what I set out to do, and I learned a lot, but my experience has been that Mathematica Home 10.1 can't handle the original 5MP images on my MacBook Pro with a 2.8GHz dual-core i7. It never seems to finish, while using hardly anything of the 16GB available memory and 30% of the CPU. I'll need to look at other tools to handle the 50 or so 5MP images I'm wanting to stitch.