Page 1 of 1

stitch tiles (overlap) to complete map

Posted: 2014-07-03T00:49:12-07:00
by Rye
So. I have the following question:

I have multiple parts of an image, like so:

Image Image

and want to "stitch them" together in order to make up one big image.

Problem is: I have overlappings in those images.

Is there a way to have imagemagick correctly assume where to overlap and output a image ?

+ will this work with directories of 100 or even 1000's of images ?

Thanks in advance.

EDIT: So you can see "the overlap", here is the way it *should* look:


Re: stitch tiles (overlap) to complete map

Posted: 2014-07-03T03:56:27-07:00
by snibgo
[Mod note: the consultancy forum is for paid consulting, so I've moved this to Users.]

Looking at the first two images, a simple translation is required. See my page "What translation?"

I can't see how the 3rd and 4th images ovelap with each other or the first two.

To align the first two, I would do this (Windows BAT script):

Code: Select all

set SRC1=IMG_8134.png
set SRC2=IMG_8135.png

%IM%convert ^
  %SRC1% ^
  -define distort:viewport=500x300-100-100 -distort SRT 1,0 +repage ^

%IM%convert ^
  %SRC2% ^
  -define distort:viewport=500x300-100-100 -distort SRT 1,0 +repage ^

call %PICTBAT%whatTrans e1.png e2.png

%IM%convert %SRC1% -repage +%wtX%+%wtY% %SRC2% -layers merge out.png
This uses my whatTrans.bat, which needs the inputs to be the same size and to have a larger overlap than your images, so I extended them both with distort.

This takes about 1 second, so would be feasible for thousands of images.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-03T19:26:35-07:00
by anthony
There was long topic on this type of thing, IE: stiching images that are 100% perfect matches without distortions.
That is overlaping images that generally come from games and screenshots of games.


A script that came out of that, which I still use at various times.

The script is called 'overlap' and is downloadable from IM Examples, Script area

This should find all the overlaps. Considering how repeative this game appears in it world generation, a lot of false matches are likly, unless you have a rough idea of the order in which images will overlap.

Snibo I can see how the 3 and 4 images overlap, though it isn't by very much.

And WOW.. your site has continued to develop in a lot of areas. Love to see some of that work incorperated into IM Examples, but I have no time to devote to that. I will be studying your stuff a lot more however.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-03T20:31:13-07:00
by snibgo
Ah, yes, I now see that #3 joins to the right of #1, and #4 joins to the right of #3. The overlaps are too small for my script to find. I wrote whatTrans.bat for adjacent video frames, or still photos, with much larger overlaps (and where no perfect match will be found).

Feel free to adapt anything on my pages for your invaluable IM Examples. I keep thinking of new things I want to add, but not enough time. Sigh.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-04T05:54:26-07:00
by Rye
So for that script you posted:

How would a command look for my case ?

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-06T18:20:38-07:00
by anthony
NOTe this is a linux/UNIX script...

overlap image_1.png image_2.png image_3.png image_4.png

The first image should be the largest 'merged image' created so far.

The output image is merged_001.png .... merged_003.png
with each merger hadding one more 'match', and the script using that last output for testing it against the next image in the list.

In other words the first command is equivlent to
overlap image_1.png image_2.png
overlap merged_001.png image_3.png
overlap merged_002.png image_4.png

Adding a -v will display verbose information of the points and offsets it find and uses to attempt a match, it only thinks it succeeds if three identical matches from the second image are found in the first image for each image being merged.

Points searched for are high entropy points that are as widly spaced across the image as posible. That is first will be in one corner, The next attempt second will be based on a high entropy point in another corner, and so on. This means it may have to go though a 10 or more attempts before it find the 3 matches.

There are options to specify a single 'high entropy' point, the radius around that point, or a area that overlaps, that is located in the second image, to search for in the first image to find the 'overlap'.

I found it works very well, and not too slow. However remember this is ment only for images which match almost perfectly, and only differ by a integer translation (offset).

Fo an example of results of this script see...
Note the haphazard way in which the overlapping maps 'fitted' together, sometimes with gaps. The script failed with some ocean maps (not many entropy points) but corrected itself when other maps linked the ocean shores around the edge.

Aside the game is minecraft, and I pretty well mapped all of this area myself.

Now in-game maps are arranged as a grid without overlaps, so I don't use the 'overlap' script as much as I used to.
For example.. Grid (appened) map in later games.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T03:13:42-07:00
by Rye
OH... so it's linux only...

Can wildcards be used so I can use a folder full of randomly named png files ?

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T06:34:33-07:00
by snibgo
Anthony's script is bash, so it runs under Unix or Mac, or (probably) Windows with Cygwin.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T07:26:30-07:00
by Rye
Is this overlap script:

the same one ?

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T07:32:22-07:00
by snibgo
Yes, that is Anthony's script.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T07:51:23-07:00
by Rye
But the one I posted is dos, isn't it ?

Is the usage the same ?

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T08:49:59-07:00
by snibgo
What one you posted? If the first line is "#!/bin/bash", it is bash.

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T09:47:54-07:00
by Rye
And I take it, rewriting it for dos is impossible ?

All of the Imgmagickscripts I have run natively under windows.

I'd rather not install cygwin just for this one script

Re: stitch tiles (overlap) to complete map

Posted: 2014-07-07T17:26:56-07:00
by anthony
snibgo's scripts are DOS. mine if LINUX bash.

I am not very familar with snibgo's scripts at this time.

The commands used in my script was discussed in the thread previously mentioned, though it is mostly about finding a set of well distributed high entropy points as a center point for small sub-image searches. That is using a 'distance gradient' generated from previously seen points, and merging it with the high-entropy edges to figure out the next high entropy point to use.

There is no reason why this could not be done in DOS, but getting someone to write it is a completely different matter.