Re: Overlapping images to form a composite

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
kenthompson1
Posts: 4
Joined: 2020-01-19T15:34:53-07:00
Authentication code: 1152

Re: Overlapping images to form a composite

Post by kenthompson1 »

I am new to Magick, so forgive my ignorance. I've read the forums and the documentation on how one might append partially-overlapping images to form a composite.

I have a series of images taken parallel to a surface. The images are taken at a fixed distance of 15mm from each other (along the Y axis), so each image overlaps by at least some amount. An example of 3 such images is here: https://photos.app.goo.gl/SZCJHzN56rXf7jnP7

I would like to 'append' a large number of images in this fashion. When I execute the example append from the documentation and forums, it appears to be premised on just two images for appending (see below). Is there a way to append a large number of images to each other with this overlap approach? Ultimately, I am trying to form a large panorama.

magick convert tmp\IMG_20200119_135301.jpg tmp\IMG_20200119_135303.jpg tmp\IMG_20200119_135305.jpg tmp\IMG_20200119_135306.jpg tmp\IMG_20200119_135308.jpg tmp\IMG_20200119_135310.jpg tmp\IMG_20200119_135311.jpg tmp\IMG_20200119_135313.jpg tmp\IMG_20200119_135315.jpg tmp\IMG_20200119_135316.jpg tmp\IMG_20200119_135318.jpg tmp\IMG_20200119_135319.jpg tmp\IMG_20200119_135321.jpg tmp\IMG_20200119_135322.jpg tmp\IMG_20200119_135324.jpg tmp\IMG_20200119_135326.jpg tmp\IMG_20200119_135327.jpg tmp\IMG_20200119_135329.jpg tmp\IMG_20200119_135330.jpg tmp\IMG_20200119_135332.jpg -gravity east -background none ^ ( -clone 1 -chop 30x0 ) ( -clone 0,2 +append ) ^ -delete 0,2 +swap -composite result.jpg

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

Re: Re: Overlapping images to form a composite

Post by snibgo »

The Hugin toolset can automatically calculate the overlaps, and blend the photos together, even accounting for lens distortions.

To do it with ImageMagick, you would:

1. Manually find the exact overlaps, or use a script for this.

2. Either crop the excess from all the images except one and append them, or do an alpha blend between each adjacent pair.

The tape measure isn't a plane, so that would confuse automated alignment.
snibgo's IM pages: im.snibgo.com

kenthompson1
Posts: 4
Joined: 2020-01-19T15:34:53-07:00
Authentication code: 1152

Re: Re: Overlapping images to form a composite

Post by kenthompson1 »

snibgo wrote:
2020-01-19T16:07:58-07:00
The Hugin toolset can automatically calculate the overlaps, and blend the photos together, even accounting for lens distortions.

To do it with ImageMagick, you would:

1. Manually find the exact overlaps, or use a script for this.

2. Either crop the excess from all the images except one and append them, or do an alpha blend between each adjacent pair.

The tape measure isn't a plane, so that would confuse automated alignment.
I am OK with finding the overlap manually- but my question is how do I then call magick to properly append the images? For instance, lets say I just want the append operation to overlap each image by an arbitrary 100 pixels. I used Hugin, but I want something automated that I can call from the command line (in my case from a python script). Thanks very much for the response

User avatar
fmw42
Posts: 26286
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Re: Overlapping images to form a composite

Post by fmw42 »

You can append multiple images, but the -append does not permit blending. So they simply abut to each other. If you need to blend, then here is a link to how to do it for a pair of images. But you need to align them first.

https://imagemagick.org/discourse-serve ... ap#p171803

ImageMagick does not have any tools specifically designed for your purposes. One would have to do it by scripting.

As user snibgo points out, Hugin and other such tools are specifically designed to do all that.

User avatar
fmw42
Posts: 26286
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Re: Overlapping images to form a composite

Post by fmw42 »

If you are calling this from Python, then you should probably check out Python OpenCV to do that. I think it has more tools designed to do what you need.

See https://www.pyimagesearch.com/2018/12/1 ... nd-python/ as one example

kenthompson1
Posts: 4
Joined: 2020-01-19T15:34:53-07:00
Authentication code: 1152

Re: Re: Overlapping images to form a composite

Post by kenthompson1 »

fmw42 wrote:
2020-01-19T16:15:31-07:00
If you are calling this from Python, then you should probably check out Python OpenCV to do that. I think it has more tools designed to do what you need.

See https://www.pyimagesearch.com/2018/12/1 ... nd-python/ as one example
I have the open CV tools operational but the results are less than satisfactory. I am stitching far too many images for openCV to do the work in a reasonable amount of time, regardless of the settings I use. The results are often poor given openCV does not handle the parallel captures very well- this is a known issue.

It sounds like I need to keep looking for something that will fit the bill.

ken

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

Re: Re: Overlapping images to form a composite

Post by snibgo »

Suppose the first pair overlap by 110 pixels, and the second by 120. You can crop and append like this:

Code: Select all

magick ^
  IMG_20200119_135301.jpg -auto-orient ^
  -gravity East ^
  ( IMG_20200119_135303.jpg ^
    -auto-orient -crop %%[fx:w-110]x+0+0 +repage ) ^
  ( IMG_20200119_135305.jpg ^
    -auto-orient -crop %%[fx:w-120]x+0+0 +repage ) ^
  +append ^
  out.png
Windows BAT syntax. For bash, change ^ to \, and %% to %, and ( ) to \( \).
snibgo's IM pages: im.snibgo.com

kenthompson1
Posts: 4
Joined: 2020-01-19T15:34:53-07:00
Authentication code: 1152

Re: Re: Overlapping images to form a composite

Post by kenthompson1 »

snibgo wrote:
2020-01-19T17:05:46-07:00
Suppose the first pair overlap by 110 pixels, and the second by 120. You can crop and append like this:

Code: Select all

magick ^
  IMG_20200119_135301.jpg -auto-orient ^
  -gravity East ^
  ( IMG_20200119_135303.jpg ^
    -auto-orient -crop %%[fx:w-110]x+0+0 +repage ) ^
  ( IMG_20200119_135305.jpg ^
    -auto-orient -crop %%[fx:w-120]x+0+0 +repage ) ^
  +append ^
  out.png
Windows BAT syntax. For bash, change ^ to \, and %% to %, and ( ) to \( \).
Thank you sir- that is exactly what I was looking for. I need to experiment a bit more, but this is looking very promising.

Post Reply