Page 1 of 1

Montage can't swap

Posted: 2010-02-03T12:33:04-07:00
by snibgo
Why can't montage use the "swap" option?

I want to extend a 360-degree panorama by glueing a crop from the right to left, and another crop from the left to the right. To avoid re-reading the input file, I want to use clone, something like:

Code: Select all

montage ^
  input.png ^
  ( +clone -gravity East -crop 10x100+0+0%%! +repage ) ^
  ( +clone -crop 10x100+0+0%%! +repage ) ^
  -swap 0,1 -tile x1 -geometry +0+0 out.png
Montage objects to the "swap", but I can't see a logical reason for this.

(6.5.8-8 Q16 on Windows 7.)

Re: Montage can't swap

Posted: 2010-02-03T12:37:06-07:00
by magick
ImageMagick support two types of command line parser depending on the utility. Convert uses the post-fix parser and montage uses the pre-fix parser. The swap option is only supported by the post-fix parser.

Re: Montage can't swap

Posted: 2010-02-03T13:07:09-07:00
by snibgo
Ah, thanks. Is the pre-fix/post-fix distiction documented somewhere? Are there plans to "regularise" the parsers across the utilities?

I realise my code above would need work even if "swap" worked with Montage. This code does what I want::

Code: Select all

montage ^
  ( input.png -gravity East -crop 10x100+0+0%%! +repage ) ^
  input.png ^
  ( input.png -gravity West -crop 10x100+0+0%%! +repage ) ^
  -tile x1 -geometry +0+0 out.png
but this eats memory, as input.png is 22878 x 3293 pixels. I could use Q8 instead, to halve the memory use. And I could generate the crops from separate commands. Any other solutions for this problem?

Re: Montage can't swap

Posted: 2010-02-03T13:20:57-07:00
by magick
We choose a parser for each command-line utility depending on what we're trying to accomplish. For montage we need to act on an image as it appears on the command-line (pre-fix parser) whereas with convert we delay action on the image filename until the command line is consumed (post-fix parser) or if a close parenthesis is encountered.

Concerning memory. ImageMagick Q8 consumes about 1/2 as much memory as Q16, however, you can also use resource limits. For example, add -limit area 4GB to your command line to force large images to cache to disk rather than memory. The command runs slower but it stops it from consuming your memory and possibly slowing down system performance. You can even set limits in the policy.xml file if you want to set a global memory limit, for example.

Re: Montage can't swap

Posted: 2010-02-03T13:36:16-07:00
by snibgo
Thanks for the explanation.

I want to avoid caching to disk, as that kills performance of IM and my computer in general. input.png is 75 M pixels. At 8 bytes per pixel, replicated 3 times, it needs 1.8 GB, which sometimes gives me the disk-caching dead-computer syndrome. I suspect I'll go the multiple command route (one convert to create the two small crops, then one montage to glue the left-crop, input and right-crop together).

Thanks again.