How to stitch images together which have overlapping?
-
- Posts: 4
- Joined: 2016-03-29T22:24:29-07:00
- Authentication code: 1151
How to stitch images together which have overlapping?
So I've got 8 images, and I need to stitch them together vertically/horizontally but only in one direction. They've got 10% overlap (i.e. 10% area is common in two adjacent images), so I can't simply use append. I'm a beginner in ImageMagick so I need some help.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to stitch images together which have overlapping?
Do the images have transparency?
What do you want to do with the overlaps? A simple alpha-blend might work, so one side of the overlap comes from one image, the other side from the other image, with a blend between them. For some images, a Minimum Error Boundary Cut works well. There are many possibilities. I show some methods on my "Dark paths" and "Blending Pyramids" pages.
If you show some example images, advice might be more specific.
What do you want to do with the overlaps? A simple alpha-blend might work, so one side of the overlap comes from one image, the other side from the other image, with a blend between them. For some images, a Minimum Error Boundary Cut works well. There are many possibilities. I show some methods on my "Dark paths" and "Blending Pyramids" pages.
If you show some example images, advice might be more specific.
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2016-03-29T22:24:29-07:00
- Authentication code: 1151
Re: How to stitch images together which have overlapping?
I just want to create a panorama/mosiac of the images. I could do the job with a photo editor but there's lots of data.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to stitch images together which have overlapping?
There are lots of ways to merge. Snibgo is just trying to pin down the method you might prefer. A small set of images might help. You can post to some free hosting service and put the URLs here. Also always provide your IM version and platform, since syntax may differ.
If you read his web pages on the relevant topics, you can ask more explicit question.
To start, you either need to match a subsection of one image in the overlay with the full overlap in the other image (see compare) or find small high detail regions in one image overlap and match each to the correspond feature in the other image,
Once you know the offset, then you have to choose between blending and a seam merge or a combination.
All this is quite complex in IM, since there is no one function to do that. So you will have to script it.
You might be better off using some panorama stitching tool. Search Google. There are a number of them.
If you read his web pages on the relevant topics, you can ask more explicit question.
To start, you either need to match a subsection of one image in the overlay with the full overlap in the other image (see compare) or find small high detail regions in one image overlap and match each to the correspond feature in the other image,
Once you know the offset, then you have to choose between blending and a seam merge or a combination.
All this is quite complex in IM, since there is no one function to do that. So you will have to script it.
You might be better off using some panorama stitching tool. Search Google. There are a number of them.
-
- Posts: 4
- Joined: 2016-03-29T22:24:29-07:00
- Authentication code: 1151
Re: How to stitch images together which have overlapping?
Thank you for your response. I should have made it very clear that I just wanted to plain overlap images over other. Turns out this code:fmw42 wrote:There are lots of ways to merge. Snibgo is just trying to pin down the method you might prefer. A small set of images might help. You can post to some free hosting service and put the URLs here. Also always provide your IM version and platform, since syntax may differ.
If you read his web pages on the relevant topics, you can ask more explicit question.
To start, you either need to match a subsection of one image in the overlay with the full overlap in the other image (see compare) or find small high detail regions in one image overlap and match each to the correspond feature in the other image,
Once you know the offset, then you have to choose between blending and a seam merge or a combination.
All this is quite complex in IM, since there is no one function to do that. So you will have to script it.
You might be better off using some panorama stitching tool. Search Google. There are a number of them.
Code: Select all
montage -geometry <offsets> a.png b.png o.png
I would like to ask you, is their anyway I could calculate these alignment offsets through imagemagick? Let me make what I want to do more clear. Say I have two different images of stars, but in the two images there is a significant amount of similar stars (overlap). Now I want to make one image out of these two. I'll do that by using montage. But I also need to calculate the horizontal and vertical offset so that the images are correctly aligned. Is there a way to do that automatically?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to stitch images together which have overlapping?
You need to crop out a subset of the overlap region in one image and compare it to the full overlap from the other image. That will give you the offsets. See compare
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
If the x or y does not shift much than you can restrict the search area appropriately to cut down time.
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
If the x or y does not shift much than you can restrict the search area appropriately to cut down time.
-
- Posts: 4
- Joined: 2016-03-29T22:24:29-07:00
- Authentication code: 1151
Re: How to stitch images together which have overlapping?
You're a magician!fmw42 wrote:You need to crop out a subset of the overlap region in one image and compare it to the full overlap from the other image. That will give you the offsets. See compare
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
If the x or y does not shift much than you can restrict the search area appropriately to cut down time.
I think I got the idea. Suppose I need to align images a.png and b.png, and both images are greyscale. I could use brute force by adding black region to the two corners of b.png until the difference gets minimum, but that would be computationally costly (binary search would help, though). How would you do it?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to stitch images together which have overlapping?
I have no idea what you are asking. There is no need to add black to use compareI think I got the idea. Suppose I need to align images a.png and b.png, and both images are greyscale. I could use brute force by adding black region to the two corners of b.png until the difference gets minimum, but that would be computationally costly (binary search would help, though). How would you do it?
Code: Select all
compare -metric rmse -subimage-search smallimage largeimage null:
You just need to crop the one image overlap region to some subset around the best viewed star pattern as the smallimage . Then search the overlap subsection in the other image as the largeimage.
If you have something else in mind, please clarify furhter or provide diagrams or actual images for us to see and test.
If you are on Unix (Linux, Mac OSX, or Windows w/Cygwin), then I have some fast correlation scripts on the link below including normalized cross correlation. The run order of magnitude time faster than IM compare.
See also
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
http://www.fmwconcepts.com/imagemagick/ ... TCHING.pdf