Page 1 of 1

Any Imagemagick hardware and customization tips?

Posted: 2015-01-19T15:33:09-07:00
by chaoscarnage
I've been using ImageMagick for masking, recoloring via -clut, and resizing anywhere from several hundred to a several thousand images at a time. Ideally we would like to speed things up a bit if at all possible. I was curious if anyone had any tips on what I can do to optimize ImageMagick or its environment for these kinds of commands. Also what kind of hardware would ImageMagick would best utilize for these types of commands (CPU, GPU)?

I currently run ImageMagick on an
x86_64 Linux server with Ubuntu 14.04.1 LTS installed
CPU: Intel(R) Xeon(R) CPU X32
RAM: 8GiB System Memory DDR2 Synchronous 800 MHz
HD: 15k Sas drives
GPU: none

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-19T18:36:37-07:00
by fmw42
General considerations. Note I am not an expert on optimizing.

See viewtopic.php?f=4&t=26801. You do not say what version of Imagemagick you are using? Perhaps upgrade to the latest version and enable OpenMP. Get as much RAM as possible/practical. Get faster processors.

I do not think OpenCL (to run an GPU) will help for just masking, recoloring/clut and resizing.

You do not provide any clue to what your command line or script is like. So make sure your command line is optimized. That is combine multiple command lines into one command line. Use clones or mpr format and parenthesis processing if you have multiple commands and want to combine them into one command line. Don't save intermediate files to disk. Use these methods to avoid multiple command lines.

Put commands in the proper IM 6 syntax order.

Remove meta data if not needed using -strip or +profile.

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-21T16:39:16-07:00
by chaoscarnage
Thanks for the thorough response. One of the commands I regularly use involves taking a grey-scale image and recoloring it using separate gradient files via convert with the gradients using the -clut argument. The gradients are rarely changed. Is there anyway to keep the gradients in memory so it doesn't have to load them from the disk every time I want to convert an image into multiple colors?

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-21T17:17:35-07:00
by fmw42
To my knowledge, no. In memory format, mpr:, only stays in memory until the command finishes. However, you can create your gradient and save as MPC: format (memory mapped). Reading that over and over is supposed to be very fast. Writing it the first time is a bit slower than other formats. See

http://www.imagemagick.org/Usage/files/#mpc
http://www.imagemagick.org/Usage/files/#mpr

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-26T00:52:57-07:00
by chaoscarnage
I recolor an image with multiple gradients like so:

'convert img.png gradient_1.png -clut result_1.png'
'convert img.png gradient_2.png -clut result_2.png'
....
'convert img.png gradient_n.png -clut result_n.png'

Is there a way I can batch the process so the image to be converted stays in memory through the n recolors?

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-26T06:45:27-07:00
by snibgo
Windows BAT syntax. Adjust for other shells.

Code: Select all

convert ^
  img.png ^
  ( +clone gradient_1.png -clut +write result_1.png +delete ) ^
  ( +clone gradient_2.png -clut +write result_2.png +delete ) ^
...
  ( +clone gradient_n.png -clut +write result_n.png +delete ) ^
  NULL:
EDIT: corrected to use different gradients.

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-27T05:38:58-07:00
by chaoscarnage
snibgo wrote:Windows BAT syntax. Adjust for other shells.

Code: Select all

convert ^
  img.png ^
  ( +clone gradient_1.png -clut +write result_1.png +delete ) ^
  ( +clone gradient_2.png -clut +write result_2.png +delete ) ^
...
  ( +clone gradient_n.png -clut +write result_n.png +delete ) ^
  NULL:
EDIT: corrected to use different gradients.
I'm somewhat of a novice when it comes to shells. What would I need to change to get this working on linux?

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-27T05:51:10-07:00
by snibgo
For bash, change every ^ to \, and escape every parenthesis.

Code: Select all

convert \
  img.png \
  \( +clone gradient_1.png -clut +write result_1.png +delete \) \
  \( +clone gradient_2.png -clut +write result_2.png +delete \) \
...
  \( +clone gradient_n.png -clut +write result_n.png +delete \) \
  NULL:

Re: Any Imagemagick hardware and customization tips?

Posted: 2015-01-27T11:16:12-07:00
by fmw42
If you convert your gradients once to mpc format and save them (with the corresponding .cache file) and do not upgrade IM, then using gradient_1.mpc ... gradient_N.mpc in your command should save time reading the gradients if you have to run this command for many input images. If you have to upgrade IM, then you may have to regenerate the gradient_X.mpc files.