Fred's ImageMagick Scripts


    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at:

    Please read the Pointers For Use on my home page to properly install and customize my scripts.


Generates a pseudocolored image or pseudocolored animation from grayscale image using a rainbow colored transformation.

Download Script

last modified: December 15, 2018

USAGE: pseudocolor [-o offset] [-i increment] [-d delay] [ -r resize] [-v] infile [outfile]
USAGE: pseudocolor [-h or -help]

-o ... offset ..... offset of rainbow colors (single frame only);
................... 0 to 255; default=0
-i ... increment .. incremental shift of rainbow colors per animation frame;
................... -128 to 128; default=-8 if no outfile provided;
................... value of -8 for animation creates 33 frames;
................... default=0 with outfile indicates single frame output
-d ... delay ...... time delay per animation frame (ms); delay >= 0; default=10
-r ... resize ..... image resize percentage; resize > 0;
................... default=100 (unchanged)
-v ................ indicates to view (display) the animation automatically
outfile ........... if no oufile is provided, a default 33 frame animation will
................... be generated and viewed (displayed) automatically without
................... specifying the -v option

PURPOSE: To generate a pseudocolored image or pseudocolored animation from grayscale image using a rainbow colored transformation.

DESCRIPTION: PSEUDOCOLOR generates a rainbow colored look up table image and applies it to a grayscale image to generate either a single frame psuedocolored output image or a pseudocolored animation. Each frame of the animation uses a different incremental roll of the rainbow color look up table. For a single frame pseudocolored output, the rainbow color look up table may be rolled by a user specified amount. The animation may be viewed (displayed) automatically with or without the saved animation file.


-o offset ... OFFSET is the pixel roll amount of the rainbow color look up table to be used for a single frame output image. If an animation is to be generated by specifying an increment value other than 0, then the offset will be ignored. Values for offset may be integers between 0 and 255 for the length 256 look up table. The default=0.

-i increment ... INCREMENT is the pixel roll amount of the rainbow color look up table to be used for each new frame of the animation. Increment values should be integers between -128 and 128. The sign indicates which direction to roll the look up table. The suggested value of -8 creates a 33 frame animation. The default=0 indicates that a single frame output image will be generated.

-d delay ... DELAY is the time delay in msec between frames in the animation. Values are integers greater than or equal to zero. The default=10. Note that the animation will be created to loop forever.

-r resize ... RESIZE allows the output animation to made larger or smaller than the input image size. The values are integers greater than 0 representing the resize percentage. The default=100 which leaves the animation the same size as the input image.

outfile ... OUTFILE if provided must be in a format such as gif that supports multiframe animations.

-v ... Specifies that along with the output animation, the animation is to be viewed (displayed) automatically before the script is ended. If no output animation file is provided, the animation will be created and viewed automatically even if the -v option is not specified. This parameter is ignored if the output is a single frame image.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


Simple Pseudocolor Of Grayscale Image

Original Grayscale Image

Pseudocolored Image
Arguments: -o 77

Rainbow LUT

Pseudocolored Animation Of Grayscale Image

Original Grayscale Image

Pseudocolored Image
Arguments: -i 8

Animated Rainbow LUT

What the script does is as follows:

  • Creates a gradient for the hue channel
  • Creates a constant image for the lightness and saturation channels
  • Merges the 3 channels into an HSL image and then converts to a
    rainbow colored RGB LUT image
  • Rotates the rainbow LUT image as desired
  • Then applies the rainbow LUT to the image to change its grayscale
    values in each channel using -clut (or -fx for older IM versions)

This is equivalent to the following IM commands for a single frame
output with an offset of 77 of the colormap and a current version
of IM (that uses -clut in place of -fx):

  • convert -size 1x256 gradient: $tmp0
  • convert -size 1x256 xc:"rgb(255,255,255)" -channel Green -separate $tmp1
  • convert -size 1x256 xc:"rgb(255,255,255)" -channel Blue -separate $tmp2
  • convert $tmp0 -colorspace HSB \
    $tmp0 -compose CopyRed -composite \
    $tmp1 -compose CopyGreen -composite \
    $tmp2 -compose CopyBlue -composite \
    -colorspace RGB $tmp3
  • convert $infile $tmp3 \( $tmp3 -roll -77+0 \) -clut $outfile