Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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: http://www.imagemagick.org/script/license.php

HUEMAP


Transforms the hues in an image from one range to another.

Download Script

last modified: September 12, 2015



USAGE: huemap [-h hues] [-t tolers] [-r] infile outfile
USAGE: huemap [-help]

-h .... hues ....... hues=srchue,dsthue; source and destination hue values;
.................... comma separated list; 0<=integer<=360; default=240,120
.................... maps blue to green
-t .... tolers ..... tolers=stoler,dtoler; source and destination range of
.................... hues on each side of hue values; 0<=integer<=360;
.................... default=10,10
-r reverse direction of range of destination hues

PURPOSE: To transform the hues in an image from one range to another.

DESCRIPTION: HUEMAP transform the hues in an image from one range to another. One hue can be mapped to another single hue. One range of hues can be mapped to a single hue. Or one range of hues can be mapped to another range of hues. This is similar to GIMP's Rotate Hues.

ARGUMENTS:

-h hues ... HUES=SRCHUE,DSTHUE. These are source and destination hue values in the range of 0<=integer<=360. The source hue (range) will be replaced by the detination hue (range), depending upon the tolers values below. The default=240,120 maps blue to green.

-t tolers ... TOLERS=STOLER,DTOLER. These are the source and destination ranges on each side of the specified hues that determine the range of hues to be mapped. Values are in the range of 0<=integer<=360. The default=10,10.

-r ... REVERSE the direction of the range of destination hues.

REQUIREMENT: IM version 6.3.5-7 or higher due to the use of -clut.

NOTE: If the image has an alpha channel, it will be copied unchanged to the output 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.


REFERENCE CHART


convert \( -size 151x151 xc:"rgb(100%,0%,0%)" -colorspace hsl \) \
\( -size 100x300 gradient: -rotate 90 +distort Polar '75,0,.5,.5' +repage -rotate 90 \) \
-compose CopyRed -composite -colorspace RGB \
\( -size 151x151 xc:black -fill white -draw "circle 75.5,75.5 75.5,151" -alpha off \) \
-compose copy_opacity -composite polar_rainbow_white.jpg


EXAMPLES


Original Image

Original Image
(http://phong.informatik.uni-leipzig.de/~kuska/oglscript/EarthMap.png)

 

Arguments:
-h 225,0 -t 50,0
Arguments:
-h 225,0 -t 50,0

 

Arguments:
-h 225,0 -t 50,50
Arguments:
-h 225,0 -t 50,50

 

Arguments:
-h 225,0 -t 50,50 -r
Arguments:
-h 225,0 -t 50,50 -r

 

Arguments:
-h 225,120 -t 50,50
Arguments:
-h 225,120 -t 50,50

 

Arguments:
-h 225,120 -t 50,50 -r
Arguments:
-h 225,120 -t 50,50 -r

 

Arguments:
-h 60,300 -t 20,20
Arguments:
-h 60,300 -t 20,20

 



What the script does is as follows:

  • Converts image to HSL colorspace and separates channels
  • Maps a range of values in the hue channel to another range of values
    using a modified gradient lut and -clut
  • Combines the HSL channels back to an RGB image

This is equivalent to the following IM commands.

  • convert $tmpI1 -colorspace HSL -channel R -separate $tmpH1
  • convert $tmpI1 -colorspace HSL -channel G -separate $tmpS1
  • convert $tmpI1 -colorspace HSL -channel B -separate $tmpL1
  • convert -size 1x360 gradient: -rotate 90 $tmpG1
  • dst1=`convert xc: -format "%[fx:($dsthue-$dtoler)]" info:`
  • dst2=`convert xc: -format "%[fx:($dsthue+$dtoler)]" info:`
  • len=$((2*$stoler+1))
  • dst1=`convert xc: -format "%[fx:100*$dst1/360]" info:`
  • dst2=`convert xc: -format "%[fx:100*$dst2/360]" info:`
  • convert -size ${len}x1 gradient:"gray($dst1%)"-"gray($dst2%)" \
    -channel red -evaluate set 0 +channel \
    -background none -gravity west -extent 360x1 $tmpT1
  • src1=`convert xc: -format "%[fx:$srchue-$stoler]" info:`
  • sign=`convert xc: -format "%[fx:sign($src1)<0?0:1]" info:`
  • abs_src1=`convert xc: -format "%[fx:abs($src1)]" info:`
  • if [ $sign -eq 0 ]; then
    rollval="-${abs_src1}+0"
    else
    rollval="+${abs_src1}+0"
    fi
  • convert $tmpG1 \( $tmpT1 -roll $rollval \) \
    -compose over -composite \
    -channel G -separate +channel \
    $tmpG1
  • convert $tmpH1 $tmpG1 -interpolate nearest-neighbor -clut $tmpH1
  • convert $tmpH1 $tmpS1 $tmpL1 -set colorspace HSL -combine \
    -colorspace RGB $outfile