[ImageMagick]
[sponsor]

apply a mathematical expression an image or image channels.

For example, to extract the alpha channel of the image, use:

  convert drawn.png -fx 'a' +matte matte.png

Mathematic operators include:

  constants: QuantumRange, QuantumScale, Opaque, Transparent, Pi
  standard operators (in order of precedence):
      ^ (power), *, /, % (modulo), +, -, <<, <, <=, =, >=, >, >>, & (binary AND), | (binary OR), : (binary XOR) 
  math function name:
      abs(), acos(), asin(), atan(), ceil(), cos(), exp(), floor(), log(),
      ln(), max(), min(), rand(), sign(), sin(), sqrt(),  tan()
  color names: red, cyan, black, etc.
  color hex values: #ccc, #cbfed0, #b9e1cc00
  symbols:
      u  = first image in sequence
      v  = second image in sequence
      i  = column offset
      j  = row offset
      p  = pixel to use (absolute or relative to current pixel)
      w  = width of this image
      h  = height of this image
      r  = red value (from RGBA), of a specific or current pixel
      g  = green    ''
      b  = blue     ''
      a  = alpha    ''
      o  = opacity  ''
      c  = cyan value of CMYK color of pixel
      y  = yellow   ''
      m  = magenta  ''
      k  = black    ''
      intensity = pixel intensity
      luminosity = pixel luminosity

Specify the image source using an image index represented by u, starting at zero for the first image, (eg: u[3] is the fourth image in the image sequence). A negative image index counts images from the end of the current image sequence, for example, u[-1] refers to the last image in the sequence.

Without an index u or v represent the first and second image of the sequence. If no image is specified, the u image is used.

For example to reduce the intensity of the red channel by 50%, use.

  convert image.png -channel red -fx 'u/2.0' image.jpg

The pixels are processed one at a time, but a different pixel of a image can be specified with a pixel index represented by p. For example,

   p[-1].g      Green value of pixel to the immediate left of current
   p[-1,-1].r   Red value, diagonally left and up from current pixel

To specify an absolute position, use braces, rather than brackets.

  p{12,34}.b   is the blue pixel at image location 12,34

The other symbols specify the value you wish to retrieve.

A pixel outside the boundary of the image has a value dictated by the -virtual-pixel option setting.

The -channel setting can be used to specify the output channel of the result. If no output channel is given the result is set over all channels, except the opacity channel. For example, suppose you want to replace the red channel of alpha.png with the average of the green channels from the images alpha.png and beta.png, use:

  convert alpha.png beta.png -channel red -fx '(u.g+v.g)/2' gamma.png

Note that all the original images in the current image sequence are replaced by the updated alpha.png image.

 
© 1999-2006 ImageMagick Studio LLC