montage use several gigabytes of RAM and swap

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
contremaitre
Posts: 6
Joined: 2013-04-14T12:00:39-07:00
Authentication code: 6789

montage use several gigabytes of RAM and swap

Post by contremaitre »

Hi,

I have 400 pictures, and I would like to create 200 pictures, so 2 pictures into 1.
They all have the same resolution : 1333x1000
So my output pictures will be 1333x2000

The command is simple :
montage -geometry +0+0 -tile 1x2 *.jpg together.jpg

But it seems that this command read ALL images at once, instead of producing output one by one.
So it freeze my system by using all the available memory.

How can I solve this ?

Thanks.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: montage use several gigabytes of RAM and swap

Post by Bonzo »

You could write some code to loop through the images and use +append
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: montage use several gigabytes of RAM and swap

Post by anthony »

Unless you do otherwise this reads in ALL the images at full size. Thus at some point you use a twice the memory needed (input images plus the output image result.

You can try to concatante images in smaller chunks. Say a row at a time then appead one row at a time together. In that case the last step still needs memory of the final image times 2!

On the other hand if you start with a full output sizes image, and 'compose' the rows onto that image, you only need memory of the large destaination image plus the small (row?) image being overlaid.


However IM "stream" command can vertically append images, and only needs in a single pixel row of pixels in memory at any time! So you would generate your rows, then stream append the rows together.
See.. Really Massive Image Handling
http://www.imagemagick.org/Usage/files/#massive
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
contremaitre
Posts: 6
Joined: 2013-04-14T12:00:39-07:00
Authentication code: 6789

Re: montage use several gigabytes of RAM and swap

Post by contremaitre »

Bonzo : Yes I could write a script, but I wanted to know if there is a solution with ImageMaick first.

anthony : My output picture is small : only 1333x2000 pixels. The issue is that IM creates the 200 output pictures at the same time and not one by one.
You say I need to handle large images but this is not the case, input and outputs are quite small.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: montage use several gigabytes of RAM and swap

Post by magick »

Add -define jpeg:size=128x128 right after the montage keyword. It creates thumbnails as each image is read. Adjust the size as needed.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: montage use several gigabytes of RAM and swap

Post by anthony »

montage always reads in all images at the same time --> LARGE memory use

mogrify only reads in one image at a time --> no image merging

neither will handles 2 images at a time

You will need to write a script to append 2 images at a time.
and that makes it a scripting problem rather than a imagemagick problem.

Hmmm, xargs can grab two images at a time, but you need to add those images in the middle of the command
But it is still posible to do..

Code: Select all

ls *.jpg | xargs -r -n2 sh -c 'convert "$0" "$1"  +append  ../output/"$0"'
Add an 'echo before the 'convert' to see what the above will do without actually doing it.

I do not recommend putting the output images in the same directory as the input images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply