Any Imagemagick hardware and customization tips?

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
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Any Imagemagick hardware and customization tips?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any Imagemagick hardware and customization tips?

Post 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.
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Any Imagemagick hardware and customization tips?

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any Imagemagick hardware and customization tips?

Post 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
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Any Imagemagick hardware and customization tips?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any Imagemagick hardware and customization tips?

Post 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.
snibgo's IM pages: im.snibgo.com
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Any Imagemagick hardware and customization tips?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any Imagemagick hardware and customization tips?

Post 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:
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any Imagemagick hardware and customization tips?

Post 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.
Post Reply