Page 1 of 1

Combining Multiple Images with Fixed Offset

Posted: 2015-08-09T18:28:27-07:00
by moonpilot
Hi,

I have a collection of 800 images that I would like to stitch together. I would like to position them on top of each other with a fixed offset (+200px in vertical direction) to build up a large composite image. For example the base of image1 would be at 0px then image2 at 200px, image3 at 400px and so on.

I have tried various image stitching programs but they try to be too clever and use patterns algorithms to try and stitch them all together but just comes out looking like a mess! I just simply need to add images with a fixed offset.

Is ImageMagick capable of easily doing this and handling multiple large image files (I expect the final image will be 30,000+ pixels tall)? I have 32GB of RAM. If not could someone please recommend some alternate software that can do this.

Many Thanks!

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-09T19:10:11-07:00
by snibgo
Your numbers don't compute. 800 images, each offset by 200 pixels from the previous, sounds like 160,000 pixels just for the offsets, plus the height of the bottom image. Or perhaps I misunderstand.

If all the images can be read into memory at once, the job is simple. For example, using three built-in images, repeated twice so we have six inputs, Windows BAT syntax:

Code: Select all

convert ^
  rose: wizard: logo: rose: wizard: logo: ^
  -set page "+0+%%[fx:200*t]" ^
  -background Blue -layers Merge +repage ^
  stack.png
To do this in memory, you need 8 (or maybe only 4) bytes per input pixel and each output pixel. If you don't have enough memory it will probably still work, but using disk which is far slower.

See also http://www.imagemagick.org/Usage/layers/#layer_calc

EDIT: A more complex method that eats less memory is to crop the top 200 rows of all the images except the last. Then append these vertically, and append the final image.

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-09T19:17:57-07:00
by fmw42
I believe that Imagemagick can do that, though I have not checked your image size computation. Are you trying to offset them so that they do not overlap, but just stack together? If so there is a simple append or montage command that will do that. If not, then the mosaic or layers merge commands will allow you to specify fixed offsets, but you will need to specify each offset along with the image name. So you would have to make a long string or put the offset and filenames in a text file and use that for input. Similarly the montage command will do similarly.

Alternately, you can write a script loop to composite each image at a successive offset.

You might identify for us what OS you are using.

See for example:

http://www.imagemagick.org/Usage/layers/#append
http://www.imagemagick.org/Usage/layers/#mosaic
http://www.imagemagick.org/Usage/montage/

If you do not have enough memory to hold all the input and output images, then you will need to configure IM to use disk space to supplement your RAM. See

http://www.imagemagick.org/Usage/files/#massive
viewtopic.php?f=4&t=26801
http://www.imagemagick.org/script/resou ... nvironment

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-09T19:24:24-07:00
by fmw42
snibgo wrote:

Code: Select all

convert ^
  rose: wizard: logo: rose: wizard: logo: ^
  -set page "+0+%%[fx:200*t]" ^
  -background Blue -layers Merge +repage ^
  stack.png
Nice approach snibgo. I did not know that -set page allowed inline computations in IM 6.

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-10T03:16:53-07:00
by moonpilot
Thanks for the replies. Sorry about the confusion regarding the "30,000 pixel" comment, I just mentioned this as I believe this is the limit for JPEG images and some editing software. Although I can scale down the final image if needed.

To clarify, heres a visualisation of what I am looking for:

Image


Im glad it sounds like it is technically possible with ImageMagick. However as I understand it, I would have to manually list the names of each image into the script? That could get pretty long and complicated I imagine!

I am on Windows 8.1 64bit with 32GB RAM.

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-10T03:45:44-07:00
by moonpilot
In reality the offset is actually 381 pixels and there are 715 images each with a resolution of 1275x410 (I just simplified the numbers to make it easier to explain).

So by my calculations, the final image would be 1,275 by 21,145 pixels (((410-381)*715) + 410)

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-10T06:19:33-07:00
by snibgo
Reading all the images into memory needs 1275*410*8*715 = 3 GB, which sounds fine on your machine. Probably best not to have a million other things happening at the same time.

So we can only see a height of 29 pixels from the bottom of each image, right? Instead of "+0+%%[fx:200*t]", you would need "+0+%%[fx:21145-29*t]"

ImageMagick needs to know what input images you want. It might be all the jpegs in a certain directory, so use "/mydir/*.jpg". If you need to list them, just put the filenames in a text file, one filename per line, and your command could be:

Code: Select all

convert ^
  @myfiles.txt ^
  -set page "+0+%%[fx:21145-29*t]" ^
  -background Blue -layers Merge +repage ^
  stack.png
If you really wanted, you could write it as a drag-n-drop.

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-10T17:47:06-07:00
by moonpilot
Many thanks for the code snibgo.

Ok I have created a text file of all the file names and saved it at C:\myfiles.txt. Ive downloaded ImageMagick on Windows 64bit (ImageMagick-6.9.1-10-Q16-x64-static.exe), opened IMDisplay, now where do I paste this code exactly? Sorry its late and Ive never used ImageMagick before.

I know youve already done a lot, but would you be able to quickly talk me through what I need to do please...

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-10T18:45:21-07:00
by snibgo
Create a text file called "C:\dostuff.bat". Paste the command into it.

At the C:\ command prompt, type "dostuff".

That's it. This should create a file called stack.png. Type "stack.png" at the command prompt to see it.

If it doesn't work, copy-paste any output from the command here.

Re: Combining Multiple Images with Fixed Offset

Posted: 2015-08-11T13:13:27-07:00
by moonpilot
Woot that worked, thank you so much! :D