root / ImageMagick / trunk / www / fx.html

Revision 12206, 24.2 kB (checked in by cristy, 3 days ago)
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
4<head>
5  <style type="text/css" media="screen,projection"><!--
6    @import url("../www/magick.css");
7  //--></style>
8  <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U=" />
9  <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf" />
10  <title>ImageMagick: The Fx Special Effects Image Operator</title>
11  <meta http-equiv="Content-Language" content="en-US"/>
12  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
13  <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/>
14  <meta name="Generator" content="PHP"/>
15  <meta name="Keywords" content="the, fx, special, effects, image, operator, ImageMagick, ImageMagic, MagickCore, MagickWand, PerlMagick, Magick++, RMagick, PythonMagick, JMagick, TclMagick, Image, Magick, Magic, Wand, ImageMagickObject"/>
16  <meta name="Description" content="ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.  ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.  The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically."/>
17  <meta name="Rating" content="GENERAL"/>
18  <meta name="Robots" content="INDEX, FOLLOW"/>
19  <meta name="Generator" content="ImageMagick Studio LLC"/>
20  <meta name="Author" content="ImageMagick Studio LLC"/>
21  <meta name="Revisit-after" content="2 DAYS"/>
22  <meta name="Resource-type" content="document"/>
23  <meta name="Copyright" content="Copyright (c) 1999-2008 ImageMagick Studio LLC"/>
24  <meta name="Distribution" content="Global"/>
25  <link rel="shortcut icon" href="../images/wand.ico"  type="images/vnd.microsoft.icon"/>
26</head>
27
28<body id="www-imagemagick-org">
29  <table id="titlebar" style="width: 100%;background-color: #f5f5f5" cellpadding="0" cellspacing="0" border="0" summary="ImageMagick">
30    <tbody>
31      <tr valign="top">
32        <td align="left"><a href="../index.html"><img id="titlebar-west" src="../images/script.png" alt="[ImageMagick]" width="350" height="60" vspace="28" name="titlebar-west"/></a></td>
33        <td align="left"><a href="https://secure.networkredux.com/affiliate/idevaffiliate.html?id=146" target="1433680542"><img id="titlebar-west" src="../images/networkredux.png" alt="[sponsor]" border="0" vspace="45" name="titlebar-west"/></a></td>
34        <td width="99%"><br /> </td>
35        <td style="background-color: white" align="right"><a href="../index.html"><img src="../images/sprite.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
36        <td style="background-color: white" align="right"><a href="http://www.imagemagick.org/discourse-server/" target="1464999055"><img id="titlebar-east" src="../images/logo.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
37      </tr>
38    </tbody>
39  </table>
40
41  <table style="width: 100%" border="0" cellpadding="0" cellspacing="0" summary="">
42  <tbody>
43
44    <tr valign="top" style="height: 100%;">
45      <td id="menu" width="1%" height="100%">
46      <p><a href="#main">Skip to page contents</a></p>
47      <font size="-1">
48      <span>[</span>
49      <a href="../index.html">About ImageMagick</a>
50  <span>]</span><br /><span>[</span>
51      <a href="../www/command-line-tools.html">Command-line Tools</a>
52      <a href="../www/command-line-processing.html" class="sub">Processing</a>
53      <a href="../www/command-line-options.html" class="sub">Options</a>
54      <a href="http://www.imagemagick.org/Usage/" target="73880437" class="sub">Usage</a>
55      <a href="../www/api.html">Program Interfaces</a>
56      <a href="../www/magick-wand.html" class="sub">MagickWand</a>
57      <a href="../www/magick-core.html" class="sub">MagickCore</a>
58      <a href="../www/perl-magick.html" class="sub">PerlMagick</a>
59      <a href="../www/Magick++/" target="2057540343" class="sub">Magick++</a>
60      <a href="../www/architecture.html">Architecture</a>
61  <span>]</span><br /><span>[</span>
62      <a href="../www/install-source.html">Install from Source</a>
63      <a href="../www/install-source.html#unix" class="sub">Unix</a>
64      <a href="../www/install-source.html#windows" class="sub">Windows</a>
65      <a href="../www/binary-releases.html">Binary Releases</a>
66      <a href="../www/binary-releases.html#unix" class="sub">Unix</a>
67      <a href="../www/binary-releases.html#macosx" class="sub">Mac OS X</a>
68      <a href="../www/binary-releases.html#windows" class="sub">Windows</a>
69      <a href="../www/resources.html">Resources</a>
70  <span>]</span><br /><span>[</span>
71      <a href="../www/download.html">Download</a>
72  <span>]</span><br /><span>[</span>
73      <a href="../www/sitemap.html">Site Map</a>
74                        <a href="../www/links.html" class="sub">Links</a>
75  <span>]</span><br /><span>[</span>
76      <a href="../www/sponsors.html">Sponsors:</a>
77      <fieldset>
78  <a href="http://www.wiiusers.net" class="sponsor" target="sponsor">Wii Forums</a><!-- 200901010000 -->
79      <br />
80      <a href="http://www.callerbase.com" class="sponsor" target="sponsor">Phone Number<br />Search</a><!-- 200812010040 -->
81      <br />
82      <a href="http://www.online-kredit-index.de" class="sponsor" target="sponsor">Kredit</a><!-- 200812010120 -->
83      <br />
84      <a href="http://www.posters555.com" class="sponsor" target="sponsor">Poster</a><!-- 200903010800 -->
85      <br />
86      <a href="http://www.iceposter.com" class="sponsor" target="sponsor">Posters</a><!-- 200812010200 -->
87      <br />
88      <a href="http://meta-preisvergleich.de" class="sponsor" target="sponsor">Preisvergleich</a><!-- 200810010120 -->
89      <br />
90      <a href="http://www.imade-art.de"><img src="../images/imade_art2.jpg" alt="[Kunst bei imade-art]" width="116" height="28" border="0" name="Kunst bei imade-art"/></a> <!-- 200811010160 -->
91      </fieldset>
92      <span>]</span>
93      </font>
94      </td>
95
96      <td id="main" valign="top">
97<p class="navigation-index">[<a href="#fx">The Fx Special Effects Image Operator</a> | <a href="#anatomy">The Anatomy of an Fx Expression</a>]</p>
98
99<div style="margin: auto;">
100  <h2><a name="fx"></a>The Fx Special Effects Image Operator</h2>
101</div>
102
103<p>Use the Fx special effects image operator to apply a mathematical expression to an image or image channels.  Use Fx to:</p>
104
105<ul>
106  <li>create canvases, gradients, mathematical colormaps</li>
107  <li>move color values between images and channels</li>
108  <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li>
109  <li>merge or composite multiple images together</li>
110  <li>convolve or merge neighboring pixels together</li>
111  <li>generate image metrics or 'fingerprints'</li>
112</ul>
113
114<p>The expression can be simple--</p>
115
116<pre class="text">
117  convert -size 64x64 xc:black -channel blue -fx "1/2" fx_navy.png
118</pre>
119
120<p>Here, we convert a black to a navy blue image:</p>
121
122<p class="image">
123  <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" align="middle" alt="black" /></a>
124  <img src="../images/right.gif" width="20" height="20" align="middle" alt="==>" />
125  <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" align="middle" alt="navy" /></a>
126</p>
127
128<p>-- or complex:</p>
129
130<pre class="text">
131  convert rose.jpg \
132          -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \
133          rose-sigmoidal.png
134</pre>
135
136<p>This expression results in a high contrast version of the image:</p>
137
138<p class="image">
139  <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" align="middle" alt="rose" /></a>
140  <img src="../images/right.gif" width="20" height="20" align="middle" alt="==>" />
141  <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" align="middle" alt="rose-sigmoidal" /></a>
142</p>
143
144<p>The expression can include variable assignments.  Assignments, in most cases, reduce the complexity of an expression and permits some operations that might not be possible any other way.  For example, lets create a radial gradient with statements:</p>
145
146<pre class="text">
147  convert -size 70x70 xc: \
148          -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \
149          radial-gradient.png
150</pre>
151
152<p>These statements return this image:</p>
153
154<p class="image">
155  <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" align="middle" alt="radial-gradient" /></a>
156</p>
157<p>See <a href="http://www.imagemagick.org/Usage/transform/index.html#fx" target="1792671368">Using FX, The Special Effects Image Operator</a> for more examples on how to     apply a mathematical expression to an image or image channels.</p>
158
159<p>The next section discusses the Fx expression language.</p>
160
161<div style="margin: auto;">
162  <h2><a name="anatomy"></a>The Anatomy of an Fx Expression</h2>
163</div>
164
165<h5>The Fx Expression Language</h5>
166
167<p>The formal Fx expression language is defined in this table:</p>
168
169<pre class="text">
170  numbers: integer, floating point, or scientfic notation (+/- required, e.g. 3.81469e-06)
171  constants: e, Epsilon, QuantumRange, QuantumScale, Opaque, Pi, Transparent
172  Fx operators (in order of precedence):
173     ^ (power), *, /, % (modulo), +, -,
174     &lt;&lt;, &gt;&gt;, &lt;, &lt;=, &gt;, &gt;=, ==, !=,
175     &amp; (bitwise AND),   | (bitwise OR),
176     &amp;&amp; (logical AND),  || (logical OR),
177     ~ (logical NOT),  ?: (ternary conditional)
178  math functions:
179     abs(), acos(), alt(), asin(), atan(), atan2(), ceil(), cos(), cosh(), debug(), exp(), floor(),
180     hypot(), int(), ln(), log(), logtwo(), max(), min(), mod(), pow(), rand(), round(),
181     sign(), sin(), sinh(), sqrt(), tan(), tanh()
182  channel functions: channel(r,g,b,a), channel(c,m,y,k,a)
183  color names: red, cyan, black, etc.
184  color functions: rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()
185  color hex values: #ccc, #cbfed0, #b9e1cc00
186  symbols:
187     s = current image in sequence
188     t = scene number of current image in sequence
189     u = first image in sequence
190     v = second image in sequence
191     n = number of images in sequence
192
193     i = column offset
194     j = row offset
195     p = pixel to use (absolute or relative to current pixel)
196
197     w = width of this image
198     h = height of this image
199     z = channel depth
200
201     r = red value (from RGBA), of a specific or current pixel
202     g = green    ''
203     b = blue     ''
204     a = alpha    ''
205     o = opacity  ''
206
207     c = cyan value of CMYK color of pixel
208     y = yellow   ''
209     m = magenta  ''
210     k = black    ''
211
212     intensity = pixel intensity
213
214     hue = pixel hue
215     saturation = pixel saturation
216     lightness = pixel lightness
217     luminance = pixel luminance
218
219     page.width = page width
220     page.height = page height
221     page.x = page x offset
222     page.y = page y offset
223
224     resolution.x = x resolution
225     resolution.y = y resolution
226
227     depth = image depth
228     minima = image minima
229     maxima = image maxima
230     mean = image mean
231     standard_deviation = image standard deviation
232       (add a channel specifier to compute a statistic for that channel, e.g. depth.r)
233</pre>
234
235<h5>The Fx Expression</h5>
236
237<p>The Fx expressions includes any combination of the following:</p>
238<ul>
239<li> <em>x</em> <kbd>^</kbd> <em>y</em>:  exponentiation (<em>x<sup>y</sup></em>)</li>
240<li> <kbd>(</kbd> ... <kbd>)</kbd>:  grouping</li>
241<li> <em>x</em> <kbd>*</kbd> <em>y</em>:  multiplication (the asterisk <kbd>*</kbd> is optional, for example, <kbd>2u</kbd> or <kbd>2(x+y)</kbd> are acceptable)</li>
242<li> <em>x</em> <kbd>/</kbd> <em>y</em>:  division</li>
243<li> <em>x</em> <kbd>%</kbd> <em>y</em>:  modulo</li>
244<li> <em>x</em> <kbd>+</kbd> <em>y</em>:  addition</li>
245<li> <em>x</em> <kbd>-</kbd> <em>y</em>:  subtraction</li>
246<li> <em>x</em> <kbd>&lt;&lt;</kbd> <em>y</em>:  left shift</li>
247<li> <em>x</em> <kbd>&gt;&gt;</kbd> <em>y</em>:  right shift</li>
248<li> <em>x</em> <kbd>&lt;</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x</em> &lt; <em>y</em>,  otherwise 0.0</li>
249<li> <em>x</em> <kbd>&lt;=</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x</em> &lt;= <em>y</em>,  otherwise 0.0</li>
250<li> <em>x</em> <kbd>&gt;</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x</em> &gt; <em>y</em>,  otherwise 0.0</li>
251<li> <em>x</em> <kbd>&gt;=</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x</em> &gt;= <em>y</em>,  otherwise 0.0</li>
252<li> <em>x</em> <kbd>==</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x </em>==<em> y</em>, otherwise 0.0</li>
253<li> <em>x</em> <kbd>!=</kbd> <em>y</em>:  boolean relation, return value 1.0 if <em>x </em>!=<em> y</em>, otherwise 0.0</li>
254<li> <em>x</em> <kbd>&amp</kbd> <em>y</em>:  binary AND</li>
255<li> <em>x</em> <kbd>|</kbd> <em>y</em>:  binary OR</li>
256<li> <em>x</em> <kbd>&amp;&amp;</kbd> <em>y</em>:  logical AND connective, return value 1.0 if <em>x</em> &gt; 0 and <em>y</em> &gt; 0,  otherwise 0.0</li>
257<li> <em>x</em> <kbd>||</kbd> <em>y</em>:  logical OR connective (inclusive), return value 1.0 if <em>x</em> &gt; 0 or <em>y</em> &gt; 0 (or both),  otherwise 0.0</li>
258<li> <kbd>~</kbd><em>x</em>:  logical NOT operator, return value 1.0 if <em>not</em> <em>x</em> &gt; 0,  otherwise 0.0</li>
259<li> <kbd>+</kbd><em>x</em>:  unary plus, return 1.0*value</li>
260<li> <kbd>-</kbd><em>x</em>:  unary minus, return -1.0*value</li>
261<li> <em>x</em> <kbd>?</kbd> <em>y</em> :</b> <em>z</em>: ternary conditional expression, return value <em>y</em> if <em>x</em> != 0, otherwise <em>z</em>; only one ternary conditional permitted per statement</li>
262<li> <em>x</em> <kbd>=</kbd> <em>y</em>: assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</li>
263<li> <em>x</em> <kbd>;</kbd> <em>y</em>: statement separator </li>
264<li> <kbd>pi</kbd>:  constant (3.141659...)</li>
265<li> <kbd>e</kbd>:  constant (2.71828...)</li>
266<li> <kbd>QuantumRange</kbd>:  constant maximum pixel value (255 for Q8, 65535 for Q16)</li>
267<li> <kbd>QuantumScale</kbd>:  constant 1.0/<kbd>QuantumRange</kbd></li>
268<li> <kbd>intensity</kbd>:  pixel intensity; equivalent to 0.299*red+0.587*green+0.114*blue</li>
269<li> <kbd>hue</kbd>:  pixel hue</li>
270<li> <kbd>saturation</kbd>:  pixel saturation</li>
271<li> <kbd>lightness</kbd>:  pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</li>
272<li> <kbd>luminance</kbd>:  pixel luminance; equivalent to 0.2126*red + 0.7152*green + 0.0722*blue</li>
273<li> <kbd>red, green, blue</kbd>, etc.:  color names</li>
274<li> <kbd>#ccc, #cbfed0, #b9e1cc00</kbd>, etc.:  color hex values</li>
275<li> <kbd>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</kbd>:  color functions</li>
276<li> <kbd>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</kbd>:  symbols</li>
277<li> <kbd>abs(</kbd><em>x</em><kbd>)</kbd>:  absolute value function</li>
278<li> <kbd>acos(</kbd><em>x</em><kbd>)</kbd>:  arc cosine function</li>
279<li> <kbd>alt(</kbd><em>x</em><kbd>)</kbd>:  sign alternation function (return 1.0 if <kbd>int(</kbd><em>x</em><kbd>)</kbd> is even, -1.0 if <kbd>int(</kbd><em>x</em><kbd>)</kbd> is odd)</li>
280<li> <kbd>asin(</kbd><em>x</em><kbd>)</kbd>:  arc sine function</li>
281<li> <kbd>atan(</kbd><em>x</em><kbd>)</kbd>:  arc tangent function</li>
282<li> <kbd>atan2(</kbd><em>y</em>,<em>x</em><kbd>)</kbd>:  arc tangent function of two variables</li>
283<li> <kbd>ceil(</kbd><em>x</em><kbd>)</kbd>: smallest integral value not less than argument</li>
284<li> <kbd>channel(</kbd><em>r</em>,<em>g</em>,<em>b</em>,<em>a</em><kbd>)</kbd>: select numeric argument based on current channel</li>
285<li> <kbd>channel(</kbd><em>c</em>,<em>m</em>,<em>y</em>,<em>k</em>,<em>a</em><kbd>)</kbd>: select numeric argument based on current channel</li>
286<li> <kbd>cos(</kbd><em>x</em><kbd>)</kbd>:  cosine function</li>
287<li> <kbd>cosh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic cosine function</li>
288<li> <kbd>debug(</kbd><em>x</em><kbd>)</kbd>:  print <em>x</em> (useful for debugging your expression)</li>
289<li> <kbd>exp(</kbd><em>x</em><kbd>)</kbd>:  natural exponential function (<em>e<sup>x</sup></em>)</li>
290<li> <kbd>floor(</kbd><em>x</em><kbd>)</kbd>:  largest integral value not greater than argument</li>
291<li> <kbd>hypot(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>:  the square root of x<sup>2</sup>+y<sup>2</sup></li>
292<li> <kbd>int(</kbd><em>x</em><kbd>)</kbd>:  greatest integer function (return greatest integer less than or equal to <em>x</em>)</li>
293<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>:  natural logarithm function</li>
294<li> <kbd>log(</kbd><em>x</em><kbd>)</kbd>:  logarithm base 10</li>
295<li> <kbd>logtwo(</kbd><em>x</em><kbd>)</kbd>:  logarithm base 2</li>
296<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>:  natural logarithm</li>
297<li> <kbd>max(</kbd><em>x</em>,</b> <em>y</em><kbd>)</kbd>:  maximum of <em>x</em> and <em>y</em></li>
298<li> <kbd>min(</kbd><em>x</em>,</b> <em>y</em><kbd>)</kbd>:  minimum of <em>x</em> and <em>y</em></li>
299<li> <kbd>mod(</kbd><em>x</em>,</b> <em>y</em><kbd>)</kbd>:  floating-point remainder function</li>
300<li> <kbd>pow(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>:  power function (<em>x<sup>y</sup></em>)</li>
301<li> <kbd>rand()</kbd>:  value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</li>
302<li> <kbd>round()</kbd>:  round to integral value, regardless of rounding direction</li>
303<li> <kbd>sign(</kbd><em>x</em><kbd>)</kbd>:  return -1.0 if <em>x</em> is less than 0.0 otherwise 1.0</li>
304<li> <kbd>sin(</kbd><em>x</em><kbd>)</kbd>:  sine function</li>
305<li> <kbd>sinh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic sine function</li>
306<li> <kbd>sqrt(</kbd><em>x</em><kbd>)</kbd>:  square root function</li>
307<li> <kbd>tan(</kbd><em>x</em><kbd>)</kbd>:  tangent function</li>
308<li> <kbd>tanh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic tangent function</li>
309</ul>
310
311<p>The expression semantics include these rules:</p>
312
313<ul>
314<li>symbols are case insensitive</li>
315<li>only one ternary conditional (e.g. x ? y : z) per statement</li>
316<li>statements are assignments or the final expression to return</li>
317<li>an assignment starts a statement, it is not an operator</li>
318<li>assignments to built-ins do not throw errors and have no effect;  e.g. <kbd>r=3.0; r</kbd> returns the pixel red color value, not 3.0</li>
319</ul>
320
321<h5>Source Image</h5>
322
323<p>The default image for <kbd>p</kbd>, <kbd>r</kbd>, <kbd>g</kbd>, <kbd>b</kbd>, <kbd>a</kbd>, etc. is <kbd>s</kbd>  which refers to the current image being looked at in <a href="../www/command-line-options.html#format" target="magick-options">%[fx: ]</a> and <a href="../www/command-line-options.html#format" target="magick-options">%[pixel: ]</a> escapes.  The <kbd>-fx</kbd> image <kbd>s</kbd> defaults to the first (zeroth) image <kbd>u</kbd>.  The index of <kbd>s</kbd> is given by <kbd>t</kbd>.</p>
324
325<p>The symbol <kbd>u</kbd> refers to the first (zeroth) image in the current image sequence, <kbd>v</kbd> the second image.  Refer to a particular image in a sequence by appending its index to any image reference (usually <kbd>u</kbd>). A negative index counts from the end.  For example, <kbd>u[2]</kbd> is the third image the sequence, <kbd>u[-1]</kbd> is the last image, and <kbd>u[t]</kbd> is <kbd>s</kbd>.</p>
326
327<p>Here we reduce the intensity of the red channel by 50%:</p>
328
329<pre class="text">
330  convert image.png -channel red -fx "u/2.0" image.jpg
331</pre>
332
333<h5>Accessing Pixels</h5>
334
335<p>All color values are in the range of 0.0 to 1.0.  The alpha channel ranges from 0.0 (fully transparent) to 1.0 (fully opaque).
336
337<p>The pixels are processed one at a time, but a different pixel of a image can be specified with a pixel index represented by <kbd>p</kbd>. For example,</p>
338
339<pre class="text">
340   p[-1].g      green value of pixel to the immediate left of current
341   p[-1,-1].r   red value, diagonally left and up from current pixel
342</pre>
343
344<p>To specify an absolute position, use braces, rather than brackets.</p>
345
346<pre class="text">
347  p{12,34}.b   blue pixel value at the 12th column and 34th row of the image
348</pre>
349
350<p>The other symbols specify the value you wish to retrieve.</p>
351
352<p>Integer pixel references retrieve the color of the pixel referred to, whereas non-integer references return a blended color according to the current <a href="../www/command-line-options.html#interpolate" target="magick-options">-interpolate</a> setting.</p>
353
354
355<p>A pixel outside the boundary of the image has a value dictated by the <a href="../www/command-line-options.html#virtual-pixel" target="magick-options">-virtual-pixel</a> option setting.</p>
356
357<h5>Apply an Expression to Select Image Channels</h5>
358
359<p>Use the <a href="../www/command-line-options.html#channel" target="magick-options">-channel</a> setting 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 <kbd>alpha.png</kbd> with the average of the green channels from the images <kbd>alpha.png</kbd> and <kbd>beta.png</kbd>, use:</p>
360
361<pre class="text">
362  convert alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png
363</pre>
364
365<h5>Results</h5>
366
367<p>The <kbd>-fx</kbd> operator evaluates the given expression once for each pixel in the first image (<em>u</em>) in the sequence for each <a href="../www/command-line-options.html#channel" target="magick-options">channel</a>. The computed value is placed in a copy (clone) of that first image.  This new image replaces all images in the current image sequence.  As such in the previous example, the updated <kbd>alpha.png</kbd> replaces both the original <kbd>alpha.png</kbd> and <kbd>beta.png</kbd> images, before being saved as <kbd>gamma.png</kbd>.</p>
368
369<p>The current image <kbd>s</kbd> is initially set to the first image in the sequence (<kbd>u</kbd>), and <kbd>t</kbd> to its index, 0.  The symbols <kbd>i</kbd> and <kbd>j</kbd> define the current pixel being processed.</p>
370
371
372<p>The value escape <kbd>%[fx: ]</kbd> is evaluated once only for each image in the current image sequence, with <kbd>s</kbd> and <kbd>t</kbd> specifying which image is being referred to <kbd>i</kbd> and <kbd>j</kbd> is set to zero and the current channel is set to red (<a href="../www/command-line-options.html#channel" target="magick-options">-channel</a> is ignored).</p>
373
374<p>The color escape <kbd>%[pixel: ]</kbd> is evaluated once per image and per color channel in that image (<a href="../www/command-line-options.html#channel" target="magick-options">-channel</a> is ignored), The values generated are then converted into a color string (named color or hex color value).  The symbols <kbd>i</kbd> and <kbd>j</kbd> are set to zero and <kbd>s</kbd> and <kbd>t</kbd> define the current image.</p>
375
376      </td>
377      <td id="margin" width="1%" height="100%" valign="top" align="right">&nbsp;</td>
378    </tr>
379  </tbody>
380  </table>
381  <div id="linkbar">
382    <span id="linkbar-west">
383      <font size="-1">
384      <a href="http://www.downloadroute.com/" target="1986791758">Downloads and Opinions</a><!-- 200810010100 -->
385      </font>
386    </span>
387    <span id="linkbar-center">
388      <a href="http://www.imagemagick.org/discourse-server/" target="771959246">Discourse Server</a> &bull;
389      <a href="../www/mailing-list.html">Mailing Lists</a> &bull;
390      <a href="http://cafe.imagemagick.org" target="1258637421">Cafe</a> &bull;
391    <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi" target="241684520">Studio</a>
392    </span>
393  </div>
394  <div id="footer">
395    <span id="footer-west">&copy; 1999-2008 ImageMagick Studio LLC</span>
396  </div>
397  <div style="clear: both; margin: 0; width: 100%; "></div>
398</body>
399</html>
Note: See TracBrowser for help on using the browser.