2

I have a bunch of equal-height images in PNG format that I want to arrange horizontally into a single image, without any overlapping. I need a software that can do this either automatically (e.g. with a batch file) or with only a few mouse clicks. Neither XnView nor IrfanView seem to have this option in their batch processing repertoire. ImageMagick's montage/convert tool can do this, but it's extremely memory-inefficient and uses over 10 GB RAM for combining images with only 0.5 GP in total (at 24bpp) which is unacceptable. DipStych has a similar problem. And from what I've seen, panorama stitching software such as ICE generally can't combine images without overlapping them.

In theory this should be a trivial task: Load all images into RAM, concatenate the arrays, save to disk, done. Which software can actually do this?

7
  • 2
    A trivial implementation that you mentioned would also allocate over 10 GB in case of 0.5 GP. I'd calculate like this: 512 * 1024 * 1024 * bytes_per_pixel * image_count. This would reach 10GB in case of 7 images. I guess that imagemagick would do the job with some fine tuning. E.g: ImageMagick memory usage
    – szkj
    Commented Jul 21, 2016 at 14:31
  • Your calculation is off; 0.5 * 3 = 1.5 GB. Using the -debug cache functionality I figured out that ImageMagick allocates four times as much RAM as actually needed, and on top of that it does some weird shit where it tries to automatically convert PNGs to indexed (and possibly some other stuff) which requires additional memory. I've managed to turn off the colour space conversion but obviously this software was written by morons so I'm really looking for an alternative here since I need to be combining images with more than 12 GB in total, and I have only 32 GB RAM.
    – And G
    Commented Jul 22, 2016 at 11:58
  • Have you tried the option in IrfanView for "Create panorama image"? That just joins all of the images together, horizontally or vertically, without overlapping.
    – vclaw
    Commented Oct 21, 2016 at 1:49
  • I'd say it's possible to implement by stream-interlaving the pixel data line by line. It might even take less memory than a single picture. However, this would be a very specific implementation just for this purpose, so I doubt it exists out of the box. Sounds like a nice task for students who want to learn about memory usage, garbage collection and performance. Commented Oct 21, 2016 at 11:38
  • 1
    Are you OK with writing your own software, if no existing software is available?
    – Nicolas Raoul
    Commented Oct 24, 2016 at 2:42

3 Answers 3

1

You already mentioned imagemagick (IM). It should just work with bigger files, too. Just try it. This software by default allocates a seemingly sensible amount of memory depending on available hardware resources to facilitate fast processing of operations in main memory and not being dependent on disk access times.

First thing for you would be to use 8bit instead of 16bit colordepth version of IM (or alternatively graphicsmagick, which often works even quicker).

If you definitely want to put IM (or gm) in chains and wait longer (orders of magnitude) for completion of the task, you might want to try their "-limit" option (https://www.imagemagick.org/script/command-line-options.php#limit): as soon as relevant proposed limits are exceeded, the image pixels get allocated to disk instead of main memory.

0

You can use the Hugin tool chain as if you are stitching scans together as described at http://hugin.sourceforge.net/tutorials/scans/en.shtml where the Advanced Techniques section talks about scripted usage. You will have to do some digging into the documentation but you can force the control points, (used for aligning images), to be on the common edges of the adjacent images.

Hugin is a free, (gratis & open source), cross platform, tool chain for doing panorama stitching, focus & exposure stacking, correction & more.

Note on memory usage:

JPEG images are a compressed format so when considering memory usage any operation, (editing, converting, stitching, etc.), will use at least width pixels x height pixels x bytes_per_color x number of color channels bytes of RAM. Thus an example file I have picked at random is a jpeg with:

  • Size: 6,334,976 bytes on disk (call it 6 MB)
  • Image Size: 4896 w x 3672 h = 17 978 112 pixels
  • Mode RGB & Bits/Channel 8 = 3 bytes per pixel
  • This gives a minimum RAM requirement for the image data alone of 53,934,336 - (near enough 54 MB) for the single input image

If you are generating a new image you will need, at minimum, enough space for the input image(s) plus that for the final output image so merging 2 photos like that above will need at least 4*54 MB = 216 MB to merge just two "6 MB" Image files.

-2

long late reply, many games take a bunch of small little pictures. and toss them all into a program. that then spits out a single file. with x,y (top/left corner) and x,y (bottom,right corner) within the single file of all the pictures within the single file. and then they just reference the array of which picture to display. most likely used for animation simple animation purposes. of say gun fire (little explosion) but without the gun. gun itself, unit standing in each direction, etc... each little image generally has a transparent background, with just the needed pixels to be displayed. (diff) in essence. so overall single file is a bit more smaller. and the game programmers able to load single file into memory taking up less space. the individual little pictures can by any size / shape for most part. it is the array list it puts out with the single large file. that is important.

working with larger images on other hand. you might look at "tif" file/picture format, or look at pure file reading/writing/appending to file. without loading them all to memory. read file. write to file, read file, append to file, read file, append to file. so mim amount of memory is used.

html5 -> canvas and some javascript might work. run a multi file upload button via html5 file upload with multi option. and a javascript that keeps expanding left or right adding images next to each other onto the canvas element, and then save the canvas via download button. or auto prompt with a "download" window in selecting were to save.

2
  • OP wants a program to combine many small pictures into a big one. You're basically suggesting a program that leaves the pictures as is and just displays them with the correct alignment. This does not fit. Commented Oct 21, 2016 at 11:32
  • my bad. re-reading. it would seem wanting a "film strip" single image. Commented Oct 21, 2016 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.