stitch tiles (overlap) to complete map

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

stitch tiles (overlap) to complete map

Post by Rye » 2014-07-03T00:49:12-07:00

So. I have the following question:

I have multiple parts of an image, like so:

Image Image
ImageImage

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:

Image
Last edited by Rye on 2014-07-04T05:34:32-07:00, edited 1 time in total.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: stitch tiles (overlap) to complete map

Post by snibgo » 2014-07-03T03:56:27-07:00

[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 ^
  e1.png

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

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.
snibgo's IM pages: im.snibgo.com

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: stitch tiles (overlap) to complete map

Post by anthony » 2014-07-03T19:26:35-07:00

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.

viewtopic.php?f=1&t=22526

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
http://www.imagemagick.org/Usage/scripts/


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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: stitch tiles (overlap) to complete map

Post by snibgo » 2014-07-03T20:31:13-07:00

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.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: stitch tiles (overlap) to complete map

Post by Rye » 2014-07-04T05:54:26-07:00

So for that script you posted:

How would a command look for my case ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: stitch tiles (overlap) to complete map

Post by anthony » 2014-07-06T18:20:38-07:00

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...
Image
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.
Image
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: stitch tiles (overlap) to complete map

Post by Rye » 2014-07-07T03:13:42-07:00

OH... so it's linux only...


Can wildcards be used so I can use a folder full of randomly named png files ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: stitch tiles (overlap) to complete map

Post by snibgo » 2014-07-07T06:34:33-07:00

Anthony's script is bash, so it runs under Unix or Mac, or (probably) Windows with Cygwin.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: stitch tiles (overlap) to complete map

Post by Rye » 2014-07-07T07:26:30-07:00

Is this overlap script: http://www.imagemagick.org/Usage/scripts/overlap

the same one ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: stitch tiles (overlap) to complete map

Post by snibgo » 2014-07-07T07:32:22-07:00

Yes, that is Anthony's script.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: stitch tiles (overlap) to complete map

Post by Rye » 2014-07-07T07:51:23-07:00

But the one I posted is dos, isn't it ?

Is the usage the same ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: stitch tiles (overlap) to complete map

Post by snibgo » 2014-07-07T08:49:59-07:00

What one you posted? If the first line is "#!/bin/bash", it is bash.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: stitch tiles (overlap) to complete map

Post by Rye » 2014-07-07T09:47:54-07:00

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
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: stitch tiles (overlap) to complete map

Post by anthony » 2014-07-07T17:26:56-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply