Mike
Mike

Reputation: 31

Concatenate huge pictures

I want to concatenate eight png-pictures each in the size of 21600px x 21600px in the form of 4 x 2 pictures using any program in windows. Trying ImageMagick or GraphicsMagick resulted in an error (due to a limitation of 65500px in any dimensions).
I also tried it with gimp, but it's too much for my computer (and gimp). I prefer a light program or even a command line program. Do you have any recommendations?

Upvotes: 0

Views: 551

Answers (3)

jcupitt
jcupitt

Reputation: 11190

You could try libvips. It's a streaming image processing library -- it can decompress, process and recompress all at the same time -- so you only need enough memory for the small chunk of pixels actually being worked on.

You can join up your images from the command-line like this:

vips arrayjoin "1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png" x.png --across 4

And it'll make x.png, the result of joining up the 8 source images in a grid, with four images across. Images are laid out left-to-right and top-to-bottom, so you'll get:

1 2 3 4
5 6 7 8 

On this laptop, I see:

$ time vips arrayjoin "1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png" x.png --across 4
real    5m38.236s
user    7m9.735s
sys 0m2.851s
peak res 249mb
$ vipsheader x.png
x.png: 74976x37488 uchar, 3 bands, srgb, pngload

So it made a 70k x 40k pixel png in about five minutes and 250mb of memory. You'll find most of that time is spent in libpng compression -- tiff format would be at least three or four times faster.

On Windows, arrayjoin can join up to about 2,000 images in one operation. More than that and you'll need to assemble in stages.

You can download a Windows binary here:

https://github.com/jcupitt/libvips/releases

The docs for arrayjoin are here:

http://jcupitt.github.io/libvips/API/current/libvips-conversion.html#vips-arrayjoin

It has options for grid layout and alignment which might be useful.

Upvotes: 2

Mike
Mike

Reputation: 31

Thx for your ideas!!! Finally I concatenated the pictures with vips, the main problem was actually displaying the picture since the first computer did't have enough RAM (16 GB). It always showed the final picture (with 86'400 x 21'600 pixels) with a black line at the bottom (like this https://ibb.co/bPGHnb)

To display the picture I used a computer with 32 GB RAM. Magick couldn't display it, since it couldn't allocate sufficient RAM. But irfantview finally made it.

Upvotes: 2

fmw42
fmw42

Reputation: 53071

Your ImageMagick policy.xml file may allow you to create bigger images, if the limitation is not from PNG. See http://www.imagemagick.org/source/policy.xml

<policy domain="resource" name="width" value="10MP"/> 
<policy domain="resource" name="height" value="10MP"/> 
<policy domain="resource" name="area" value="100MP"/> 

Use:

convert -list resource

to tell you what your current values are. For example, I get

convert -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 17.18GP
  Memory: 8GiB
  Map: 16GiB
  Disk: unlimited
  File: 192
  Thread: 4
  Throttle: 0
  Time: unlimited

But if you do not have enough RAM to hold that size resulting image and the input images. You may have to use the policy.xml file to map to disk, though that will be slower.

4*21600 = 86400. So you would need approximately 87 Mpixels wide on your width limitation.

Your area would need to be 8*21600*21600 = 3732480000 or about 3.7 Mpixels area.

Also 8images*24Bytes*21600*21600=89579520000 Bytes or about 90 GB, which needs to be doubled for both input and output data. I suspect that may be larger than your RAM amount.

Note that even though your PNGs are compressed, ImageMagick has to decompress them before processing.

Upvotes: 1

Related Questions