This file is indexed.

/usr/share/doc/imagemagick/www/fx.html is in imagemagick-doc 8:6.7.7.10-6ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html version="-//W3C//DTD XHTML 1.1//EN"
      xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.w3.org/1999/xhtml
                          http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd">
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  <meta name="google-site-verification" content="MxsMq6bdLOx0KSuz1MY6yG9ZTIJ7_7DVRfl5NCAT5Yg"/>
  <title>ImageMagick: The Fx Special Effects Image Operator</title>
  <meta http-equiv="content-language" content="en-US"/>
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <meta http-equiv="reply-to" content="magick-users@imagemagick.org"/>
  <meta name="application-name" content="ImageMagick"/>
  <meta name="description" content="Use ImageMagick to convert, edit, or compose bitmap images in a variety of formats.  In addition resize, rotate, shear, distort and transform images automagically."/>
  <meta name="application-url" content="http://www.imagemagick.org"/>
  <meta name="generator" content="PHP"/>
  <meta name="keywords" content="the, fx, special, effects, image, operator, ImageMagick, PerlMagick, image processing, OpenMP, software development library, image, photo, software, Magick++, MagickWand"/>
  <meta name="rating" content="GENERAL"/>
  <meta name="robots" content="INDEX, FOLLOW"/>
  <meta name="generator" content="ImageMagick Studio LLC"/>
  <meta name="author" content="ImageMagick Studio LLC"/>
  <meta name="revisit-after" content="2 DAYS"/>
  <meta name="resource-type" content="document"/>
  <meta name="copyright" content="Copyright (c) 1999-2012 ImageMagick Studio LLC"/>
  <meta name="distribution" content="Global"/>
  <link rel="icon" href="../images/wand.png"/>
  <link rel="shortcut icon" href="../images/wand.ico"  type="images/x-icon"/>
  <link rel="canonical" href="http://www.imagemagick.org" />
  <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf"/>
  <!-- Add jQuery library -->
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
  
  <!-- Optionaly include easing and/or mousewheel plugins -->
  <script type="text/javascript" src="http://www.imagemagick.org/fancybox/jquery.easing-1.3.pack.js"></script>
  <script type="text/javascript" src="http://www.imagemagick.org/fancybox/jquery.mousewheel-3.0.6.pack.js"></script>
  
  <!-- Add fancyBox -->
  <link rel="stylesheet" href="http://www.imagemagick.org/fancybox/jquery.fancybox.css?v=2.0.4" type="text/css" media="screen" />
  <script type="text/javascript" src="http://www.imagemagick.org/fancybox/jquery.fancybox.pack.js?v=2.0.4"></script>
  
  <!-- Optionaly include button and/or thumbnail helpers -->
  <link rel="stylesheet" href="http://www.imagemagick.org/fancybox/helpers/jquery.fancybox-buttons.css?v=2.0.4" type="text/css" media="screen" />
  <script type="text/javascript" src="http://www.imagemagick.org/fancybox/helpers/jquery.fancybox-buttons.js?v=2.0.4"></script>
  
  <link rel="stylesheet" href="http://www.imagemagick.org/fancybox/helpers/jquery.fancybox-thumbs.css?v=2.0.4" type="text/css" media="screen" />
  <script type="text/javascript" src="http://www.imagemagick.org/fancybox/helpers/jquery.fancybox-thumbs.js?v=2.0.4"></script>
  <script type="text/javascript">
  	$(document).ready(function() {
  		$(".fancybox").fancybox();
  	});
  </script>
  <!-- ImageMagick style -->
  <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
  <style type="text/css" media="all">
    @import url("../www/magick.css");
  </style>
</head>

<body id="www-imagemagick-org">
<div class="titlebar">
<div style="margin: 17px auto; float: left;">
  <script type="text/javascript">
  <!--
    google_ad_client = "pub-3129977114552745";
    google_ad_slot = "5439289906";
    google_ad_width = 728;
    google_ad_height = 90;
  //-->
  </script>
  <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
  </script>
</div>
<a href="../discourse-server">
  <img src="../images/logo.jpg"
  alt="ImageMagick Logo"
  style="width: 123px; height: 118px; border: 0px; float: right;" /></a>
<a href="../index.html">
  <img src="../images/sprite.jpg"
  alt="ImageMagick Sprite"
  style="width: 114px; height: 118px; border: 0px; float: right;" /></a>
</div>

<div class="westbar">

<div class="menu">
  <a title="About ImageMagick" href="../index.html">About ImageMagick</a>
</div>
<div class="menu">
  <a title="Binary Releases" href="binary-releases.html">Binary Releases</a>
</div>
<div class="sub">
    <a title="Binary Release: Unix" href="binary-releases.html#unix">Unix</a>
</div>
<div class="sub">
    <a title="Binary Release: MacOS X" href="binary-releases.html#macosx">Mac OS X</a>
</div>
<div class="sub">
    <a title="Binary Release: iOS" href="binary-releases.html#iOS">iOS</a>
</div>
<div class="sub">
    <a title="Binary Release: Windows" href="binary-releases.html#windows">Windows</a>
</div>
<div class="sep"></div>
<div class="menu">
  <a title="Command-line Tools" href="command-line-tools.html">Command-line Tools</a>
</div>
<div class="sub">
    <a title="Command-line Tools: Processing" href="command-line-processing.html">Processing</a>
</div>
<div class="sub">
    <a title="Command-line Tools: Options" href="command-line-options.html">Options</a>
</div>
<div class="sub">
    <a title="Command-line Tools: Usage" href="http://www.imagemagick.org/Usage/">Usage</a>
</div>
<div class="menu">
  <a title="Program Interfaces" href="api.html">Program Interfaces</a>
</div>
<div class="sub">
    <a title="Program Interface: MagickWand" href="magick-wand.html">MagickWand</a>
</div>
<div class="sub">
    <a title="Program Interface: MagickCore" href="magick-core.html">MagickCore</a>
</div>
<div class="sub">
    <a title="Program Interface: PerlMagick" href="perl-magick.html">PerlMagick</a>
</div>
<div class="sub">
    <a title="Program Interface: Magick++" href="magick++.html">Magick++</a>
</div>
<div class="sep"></div>
<div  class="menu">
   <a title="Install from Source" href="install-source.html">Install from Source</a>
</div>
<div class="sub">
    <a title="Install from Source: Unix" href="install-source.html#unix">Unix</a>
</div>
<div class="sub">
    <a title="Install from Source: Windows" href="install-source.html#windows">Windows</a>
 </div>
<div class="menu">
  <a title="Resources" href="resources.html">Resources</a>
</div>
<div class="menu">
  <a title="Architecture" href="architecture.html">Architecture</a>
</div>
<div class="menu">
  <a title="Download" href="download.html">Download</a>
</div>
<div class="sep"></div>
<div class="menu">
  <a title="Search" href="search.html">Search</a>
</div>
<div class="sep"></div>
<div class="menu">
  <a title="Site Map" href="sitemap.html">Site Map</a>
</div>
<div  class="sub">
  <a title="Site Map: Links" href="links.html">Links</a>
</div>
<div class="sep"></div>
<div class="menu">
  <a rel="follow" title="Sponsors" href="sponsors.html">Sponsors:</a>

  <a href="http://www.networkredux.com"> <img src="../images/networkredux.png" width="140" height="31" alt="[sponsor]" style="margin-top: 4px; margin-left: 4px; border: 0px; float: left;" /></a>
  <a href="http://www.dinodirect.com/ipads-tablets/"> <img src="../images/dino-direct.jpg" width="140" height="90" alt="[sponsor]" style="margin-top: 4px; margin-left: 4px; border: 0px; float: left;" /></a><!-- 201208010120 mickey@163... -->
<div class="sponsbox">
<div class="sponsor">
  <a rel="follow" title="Sponsor: The Fastest &amp; Easiest Way to Find Images" href="http://www.graphicsfactory.com">The Fastest &amp; Easiest Way to Find Images</a><!-- 201210010270 graphicsfac... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: VPS" href="http://www.interdominios.com/vps">VPS</a><!-- 201209010090 barsh@inter... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Werbebanner Werbeplane" href="http://www.allesbanner.de">Werbebanner Werbeplane</a><!-- 201212010450 info@druck... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Entertainment News &amp; Photos" href="http://www.zimbio.com">Entertainment News &amp; Photos</a><!-- 201211010540 bd@zimb... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: LED24" href="http://led24.de/">LED24</a><!-- 201207010270 info@led24... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: Best Website Hosting" href="http://www.top-cheap-web-hosting.com">Best Website Hosting</a><!-- 201304010090 eunge.liu-->
</div>
<div class="sponsor">
  <a rel="follow" title="Android Tablet" href="http://www.dinodirect.com/ipads-tablets/">Android Tablet</a><!-- 201208010120 mickey@163... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: Web Site Hosting" href="http://webhostinggeeks.com">Web Site Hosting</a><!-- 201302010900 funds@enmob... -->
</div>
<div class="sponsor">
   <a rel="follow" title="Sponsor: Premium Quality Stock Photos" href="http://www.f1online.pro/en/">Premium Quality Stock Photos</a><!-- 2012080100540 ... -->
</div>
<div class="sponsor">
   <a rel="follow" title="Sponsor: Druckerei" href="http://print24.com/de/">Druckerei</a><!-- 2012070100250 ... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: Managed Server" href="http://www.robhost.de">Managed Server</a><!-- 201210010720 klikics... -->
</div>
<div class="sponsor">
  <a rel="follow" title="Sponsor: Druckerei" href="http://www.allesdruck.de">Druckerei</a><!-- 201303011500 r.leo -->
</div>
<div class="sponsor">
   <a rel="follow" title="Sponsor: Free Catalogs" href="http://www.who-sells-it.com/">Free Catalogs</a><!-- 20120801000600 -->
</div>
<div class="sponsor">
   <a rel="follow" title="Sponsor: Web Hosting" href="http://www.hostucan.com">Web Hosting</a><!-- 2012120100150 racent marketing@webhosting...-->
</div>
</div>
</div>
</div>

<div class="eastbar">
  <div class="g-plusone" id="gplusone"></div>
  <script type="text/javascript">
    window.___gcfg = {
      lang: 'en-US'
    };

    (function() {
      var po = document.createElement('script');
      po.type = 'text/javascript'; po.async = true;
      po.src = 'https://apis.google.com/js/plusone.js';
      var script = document.getElementsByTagName('script')[0];
      script.parentNode.insertBefore(po, script);
    })();
    var gplusone = document.getElementById("gplusone");
    gplusone.setAttribute("data-size","medium");
    gplusone.setAttribute("data-count","false");
  </script>
</div>

<div class="main">

<h1>Apply Special Effects to an Image with an Fx Expression</h1>
<p class="navigation-index">[<a href="fx.html#fx">The Fx Special Effects Image Operator</a> &bull; <a href="fx.html#anatomy">The Anatomy of an Fx Expression</a>]</p>

<a id="fx"></a>
<div class="doc-section">

<p>Use the Fx special effects image operator to apply a mathematical expression to an image or image channels.  Use Fx to:</p>

<ul>
  <li>create canvases, gradients, mathematical colormaps</li>
  <li>move color values between images and channels</li>
  <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li>
  <li>merge or composite multiple images together</li>
  <li>convolve or merge neighboring pixels together</li>
  <li>generate image metrics or 'fingerprints'</li>
</ul>

<p>The expression can be simple:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert -size 64x64 canvas:black -channel blue -fx "1/2" fx_navy.png</span></p>
<p>Here, we convert a black to a navy blue image:</p>

<p class="image">
  <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" alt="black" /></a>
  <img style="margin-top:22px; margin-bottom:22px;" src="../images/right.gif" width="20" height="20" alt="==>" />
  <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" alt="navy" /></a>
</p>

<p>Or the expression can be complex:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert rose.jpg \  <br/>
          -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \ <br/>
          rose-sigmoidal.png</span></p>
<p>This expression results in a high contrast version of the image:</p>

<p class="image">
  <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a>
  <img style="margin-top:13px; margin-bottom:13px;" src="../images/right.gif" width="20" height="20" alt="==>" />
  <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a>
</p>

<p>The expression can include variable assignments.  Assignments, in most cases, reduce the complexity of an expression and permit some operations that might not be possible any other way.  For example, lets create a radial gradient:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert -size 70x70 canvas: \  <br/>
          -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \ <br/>
          radial-gradient.png</span></p>
<p>The command above returns this image:</p>

<p class="image">
  <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a>
</p>

<p>This FX expression adds random noise to an image:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert photo.jpg -fx 'iso=32; rone=rand(); rtwo=rand(); \<br />
     myn=sqrt(-2*ln(rone))*cos(2*Pi*rtwo); myntwo=sqrt(-2*ln(rtwo))* \<br />
     cos(2*Pi*rone); pnoise=sqrt(p)*myn*sqrt(iso)* \ <br />
     channel(4.28,3.86,6.68,0)/255; max(0,p+pnoise)' noisy.png</span></p>
<p>See <a href="http://www.imagemagick.org/Usage/transform/index.html#fx">Using FX, The Special Effects Image Operator</a> for more examples.</p>

<p>The next section discusses the Fx expression language.</p>

</div>

<h2><a id="anatomy"></a>The Anatomy of an Fx Expression</h2>
<div class="doc-section">

<h3>The Fx Expression Language</h3>
<div class="doc-section">

<p>The formal Fx expression language is defined here:</p>

<dl class="doc">
  <dt class="doc"> numbers:</dt>
  	<dd> integer, floating point, scientfic notation (+/- required, e.g. 3.81469e-06), International System number postfixes (.e.g KB, Mib, GB, etc.)</dd>
  <dt class="doc"> constants: </dt>
    <dd> E (Euler's number), Epsilon, QuantumRange, QuantumScale, Opaque, Phi (golden ratio), Pi, Transparent</dd>
  <dt class="doc"> Fx operators (in order of precedence): </dt>
     <dd> ^ (power), unary -, *, /, % (modulo), +, -,
     &lt;&lt;, &gt;&gt;, &lt;, &lt;=, &gt;, &gt;=, ==, !=,
     &amp; (bitwise AND),   | (bitwise OR),
     &amp;&amp; (logical AND),  || (logical OR),
     ~ (logical NOT),  ?: (ternary conditional)</dd>
  <dt class="doc"> math functions: </dt>
     <dd> abs(), acos(), acosh(), airy(), alt(), asin(), asinh(), atan(), atanh(), atan2(), ceil(), cos(), cosh(), debug(), drc(), exp(), floor(), gauss(), gcd(), hypot(), int(), isnan(), j0(), j1(), jinc(), ln(), log(), logtwo(), max(), min(), mod(), not(), pow(), rand(), round(), sign(), sin(), sinc(), sinh(), sqrt(), squish(), tan(), tanh(), trunc()</dd>
  <dt class="doc"> channel functions: </dt>
    <dd> channel(r,g,b,a), channel(c,m,y,k,a)</dd>
  <dt class="doc"> color names:</dt>
    <dd> red, cyan, black, etc.</dd>
  <dt class="doc"> color functions:</dt>
    <dd> srgb(), srgba(), rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla(), etc.</dd>
  <dt class="doc"> color hex values:</dt>
    <dd> #ccc, #cbfed0, #b9e1cc00, etc.</dd>
  <dt class="doc"> symbols:</dt>
     <dd style="white-space:pre">
     s = current image in sequence
     t = scene number of current image in sequence
     u = first image in sequence
     v = second image in sequence
     n = number of images 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
     z = channel depth

     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

     hue = pixel hue
     saturation = pixel saturation
     lightness = pixel lightness
     luminance = pixel luminance

     page.width = page width
     page.height = page height
     page.x = page x offset
     page.y = page y offset

     resolution.x = x resolution
     resolution.y = y resolution

     depth = image depth
     minima = image minima
     maxima = image maxima
     mean = image mean
     standard_deviation = image standard deviation
     kurtosis = image kurtosis
     skewness = image skewness
       (add a channel specifier to compute a statistic for that channel, e.g. depth.r)
     </dd>
  <dt class="doc"> iterators:</dt>
    <dd> while()</dd>
</dl>

</div>

<h3>The Fx Expression</h3>
<div class="doc-section">

<p>An Fx expression may include any combination of the following:</p>
<ul>
<li> <em>x</em> <kbd>^</kbd> <em>y</em>:  exponentiation (<em>x<sup>y</sup></em>)</li>
<li> <kbd>(</kbd> ... <kbd>)</kbd>:  grouping</li>
<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>
<li> <em>x</em> <kbd>/</kbd> <em>y</em>:  division</li>
<li> <em>x</em> <kbd>%</kbd> <em>y</em>:  modulo</li>
<li> <em>x</em> <kbd>+</kbd> <em>y</em>:  addition</li>
<li> <em>x</em> <kbd>-</kbd> <em>y</em>:  subtraction</li>
<li> <em>x</em> <kbd>&lt;&lt;</kbd> <em>y</em>:  left shift</li>
<li> <em>x</em> <kbd>&gt;&gt;</kbd> <em>y</em>:  right shift</li>
<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>
<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>
<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>
<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>
<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>
<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>
<li> <em>x</em> <kbd>&amp;</kbd> <em>y</em>:  binary AND</li>
<li> <em>x</em> <kbd>|</kbd> <em>y</em>:  binary OR</li>
<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>
<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>
<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>
<li> <kbd>+</kbd><em>x</em>:  unary plus, return 1.0*value</li>
<li> <kbd>-</kbd><em>x</em>:  unary minus, return -1.0*value</li>
<li> <em>x</em> <kbd>?</kbd> <em>y</em> : <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>
<li> <em>x</em> <kbd>=</kbd> <em>y</em>: assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</li>
<li> <em>x</em> <kbd>;</kbd> <em>y</em>: statement separator </li>
<li> <kbd>phi</kbd>:  constant (1.618034...)</li>
<li> <kbd>pi</kbd>:  constant (3.141659...)</li>
<li> <kbd>e</kbd>:  constant (2.71828...)</li>
<li> <kbd>QuantumRange</kbd>:  constant maximum pixel value (255 for Q8, 65535 for Q16)</li>
<li> <kbd>QuantumScale</kbd>:  constant 1.0/<kbd>QuantumRange</kbd></li>
<li> <kbd>intensity</kbd>:  pixel intensity; equivalent to 0.299*red+0.587*green+0.114*blue</li>
<li> <kbd>hue</kbd>:  pixel hue</li>
<li> <kbd>saturation</kbd>:  pixel saturation</li>
<li> <kbd>lightness</kbd>:  pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</li>
<li> <kbd>luminance</kbd>:  pixel luminance; equivalent to 0.2126*red + 0.7152*green + 0.0722*blue</li>
<li> <kbd>red, green, blue</kbd>, etc.:  color names</li>
<li> <kbd>#ccc, #cbfed0, #b9e1cc00</kbd>, etc.:  color hex values</li>
<li> <kbd>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</kbd>:  color functions</li>
<li> <kbd>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</kbd>:  symbols</li>
<li> <kbd>abs(</kbd><em>x</em><kbd>)</kbd>:  absolute value function</li>
<li> <kbd>acos(</kbd><em>x</em><kbd>)</kbd>:  arc cosine function</li>
<li> <kbd>acosh(</kbd><em>x</em><kbd>)</kbd>:  inverse hyperbolic cosine function</li>
<li> <kbd>airy(</kbd><em>x</em><kbd>)</kbd>:  Airy function (max=1, min=0); airy(<em>x</em>)=[jinc(<em>x</em>)]<sup>2</sup>=[2*j1(<em>pi*x</em>)/(<em>pi*x</em>)]<sup>2</sup></li>
<li> <kbd>alt(</kbd><em>x</em><kbd>)</kbd>:  sign alternation function (return 1.0 if int(<em>x</em>) is even, -1.0 if int(<em>x</em>) is odd)</li>
<li> <kbd>asin(</kbd><em>x</em><kbd>)</kbd>:  arc sine function</li>
<li> <kbd>asinh(</kbd><em>x</em><kbd>)</kbd>:  inverse hyperbolic sine function</li>
<li> <kbd>atan(</kbd><em>x</em><kbd>)</kbd>:  arc tangent function</li>
<li> <kbd>atanh(</kbd><em>x</em><kbd>)</kbd>:  inverse hyperbolic tangent function</li>
<li> <kbd>atan2(</kbd><em>y</em>,<em>x</em><kbd>)</kbd>:  arc tangent function of two variables</li>
<li> <kbd>ceil(</kbd><em>x</em><kbd>)</kbd>: smallest integral value not less than argument</li>
<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>
<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>
<li> <kbd>cos(</kbd><em>x</em><kbd>)</kbd>:  cosine function</li>
<li> <kbd>cosh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic cosine function</li>
<li> <kbd>debug(</kbd><em>x</em><kbd>)</kbd>:  print <em>x</em> (useful for debugging your expression)</li>
<li> <kbd>drc(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>:  dynamic range compression (knee curve); drc(<em>x</em>,<em>y</em>)=(<em>x</em>)/(<em>y</em>*(<em>x</em>-1)+1); -1&lt;<em>y</em>&lt;1 </li>
<li> <kbd>exp(</kbd><em>x</em><kbd>)</kbd>:  natural exponential function (<em>e<sup>x</sup></em>)</li>
<li> <kbd>floor(</kbd><em>x</em><kbd>)</kbd>:  largest integral value not greater than argument</li>
<li> <kbd>gauss(</kbd><em>x</em><kbd>)</kbd>:  gaussian function; gauss(<em>x</em>)=exp(<em>-x*x/2</em>)/sqrt(2*pi)</li>
<li> <kbd>gcd(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>:  greatest common denominator</li>
<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>
<li> <kbd>int(</kbd><em>x</em><kbd>)</kbd>:  greatest integer function (return greatest integer less than or equal to <em>x</em>)</li>
<li> <kbd>isnan(</kbd><em>x</em><kbd>)</kbd>: return 1.0 if <em>x</em> is NAN, 0.0 otherwise</li>
<li> <kbd>j0(</kbd><em>x</em><kbd>)</kbd>:  Bessel functions of <em>x</em> of the first kind of order 0</li>
<li> <kbd>j1(</kbd><em>x</em><kbd>)</kbd>:  Bessel functions of <em>x</em> of the first kind of order 1</li>
<li> <kbd>jinc(</kbd><em>x</em><kbd>)</kbd>:  jinc function (max=1, min=-0.1323); jinc(<em>x</em>)=2*j1(pi*<em>x</em>)/(pi*<em>*x</em>)</li>
<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>:  natural logarithm function</li>
<li> <kbd>log(</kbd><em>x</em><kbd>)</kbd>:  logarithm base 10</li>
<li> <kbd>logtwo(</kbd><em>x</em><kbd>)</kbd>:  logarithm base 2</li>
<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>:  natural logarithm</li>
<li> <kbd>max(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>:  maximum of <em>x</em> and <em>y</em></li>
<li> <kbd>min(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>:  minimum of <em>x</em> and <em>y</em></li>
<li> <kbd>mod(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>:  floating-point remainder function</li>
<li> <kbd>not(</kbd><em>x</em><kbd>)</kbd>:  return 1.0 if <em>x</em> is zero, 0.0 otherwise</li>
<li> <kbd>pow(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>:  power function (<em>x<sup>y</sup></em>)</li>
<li> <kbd>rand()</kbd>:  value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</li>
<li> <kbd>round()</kbd>:  round to integral value, regardless of rounding direction</li>
<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>
<li> <kbd>sin(</kbd><em>x</em><kbd>)</kbd>:  sine function</li>
<li> <kbd>sinc(</kbd><em>x</em><kbd>)</kbd>:  sinc function (max=1, min=-0.21); sinc(<em>x</em>)=sin(<em>pi*x</em>)/(<em>pi*x</em>)</li>
<li> <kbd>squish(</kbd><em>x</em><kbd>)</kbd>:  squish function; squish(<em>x</em>)=1.0/(1.0+exp(<em>-x</em>))</li>
<li> <kbd>sinh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic sine function</li>
<li> <kbd>sqrt(</kbd><em>x</em><kbd>)</kbd>:  square root function</li>
<li> <kbd>tan(</kbd><em>x</em><kbd>)</kbd>:  tangent function</li>
<li> <kbd>tanh(</kbd><em>x</em><kbd>)</kbd>:  hyperbolic tangent function</li>
<li> <kbd>trunc(</kbd><em>x</em><kbd>)</kbd>:  round to integer, towards zero</li>
<li> <kbd>while(</kbd><em>condition</em>,<em>expression</em><kbd>)</kbd>:  interate while the condition is not equal to 0</li>
</ul>

<p>The expression semantics include these rules:</p>

<ul>
<li>symbols are case insensitive</li>
<li>only one ternary conditional (e.g. x ? y : z) per statement</li>
<li>statements are assignments or the final expression to return</li>
<li>an assignment starts a statement, it is not an operator</li>
<li>assignments to built-ins do not throw an exception and have no effect;  e.g. <kbd>r=3.0; r</kbd> returns the pixel red color value, not 3.0</li>
<li>Unary operators have a lower priority than binary operators, that is, the unary minus (negation) has lower precedence than exponentiation, so -3^2 is interpreted as -(3^2) = -9.  Use parentheses to clarify your intent (e.g. (-3)^2 = 9).</li>
<li>Similarly, care must be exercised when using the slash ('/') symbol. The string of characters <em>1/2x</em> is interpreted as (1/2)x. The contrary interpretation should be written explicitly as 1/(2x). Again, the use of parentheses helps clarify the meaning and should be used whenever there is any chance of misinterpretation.</li>
</ul>


</div>

<h3>Source Images</h3>
<div class="doc-section">

<p>The symbols <kbd>u</kbd> and <kbd>v</kbd> refer to the first and second images, respectively, in the current image sequence.  Refer to a particular image in a sequence by appending its index to any image reference (usually <kbd>u</kbd>), with a zero index for the beginning of the sequence. A negative index counts from the end.  For example, <kbd>u[0]</kbd> is the first image in the sequence, <kbd>u[2]</kbd> is the third, <kbd>u[-1]</kbd> is the last image, and <kbd>u[t]</kbd> is the current image. The current image can also be referenced by <kbd>s</kbd>. If the sequence number exceeds the length of the sequence, the count is wrapped. Thus in a 3-image sequence,  <kbd>u[-1]</kbd>, <kbd>u[2]</kbd>, and <kbd>u[5]</kbd> all refer to the same (third) image.</p>

<p>As an example, we form an image by averaging the first image and third images:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert image1.jpg image2.jpg image3.jpg -fx "(u+u[2])/2.0" image.jpg</span></p>
<p>By default, the image to which <kbd>p</kbd>, <kbd>r</kbd>, <kbd>g</kbd>, <kbd>b</kbd>, <kbd>a</kbd>, etc., are applied is the first image <kbd>u</kbd> in the image list, which may also be referenced using <kbd>s</kbd>. </p>

<p>It is important to note the special role played by the first image. This is the only image in the image sequence that is modified, other images are used only for their data. As an illustrative example, consider the following, and note that the setting <a href="command-line-options.html#channel">-channel red</a> instructs <a href="command-line-options.html#fx">-fx</a> to modify only the red channel; nothing in the green or blue channels will change. It is instructive to ponder why the result is not symmetric.</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert -channel red logo: -flop logo: -resize "20%"  -fx "(u+v)/2" image.jpg</span></p>
<div class="image">
  <a href="../images/logo-sm-flop.png"><img src="../images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a>
  <a href="../images/logo-sm.png"><img src="../images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a>
<img style="margin-top:38px; margin-bottom:38px;" src="../images/right.gif" width="20" height="20" alt="==>" />
  <a href="../images/logo-sm-fx.png"><img src="../images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a>
</div>


</div>

<h3>Accessing Pixels</h3>
<div class="doc-section">

<p>All color values are normalized to the range of 0.0 to 1.0.  The alpha channel ranges from 0.0 (fully transparent) to 1.0 (fully opaque).</p>

<p>The pixels are processed one at a time, but a different pixel of an image can be specified using a pixel index represented by <kbd>p</kbd>. For example,</p>

<pre class="text">
   p[-1].g      green value of pixel to the immediate left of the current pixel
   p[-1,-1].r   red value of the pixel diagonally left and up from current pixel
</pre>

<p>To specify an absolute position, use braces, rather than brackets.</p>

<pre class="text">
  p{0,0}.r     red value of the pixel in the upper left corner of the image
  p{12,34}.b   blue pixel value at column number 12, row 34 of the image
</pre>

<p>Integer values of the position retrieve the color of the pixel referenced, while non-integer position values return a blended color according to the current <a href="command-line-options.html#interpolate">-interpolate</a> setting.</p>

<p>A position outside the boundary of the image retrieves a value dictated by the <a href="command-line-options.html#virtual-pixel">-virtual-pixel</a> option setting.</p>

</div>

<h3>Apply an Expression to Select Image Channels</h3>
<div class="doc-section">

<p>Use the <a href="command-line-options.html#channel">-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, 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>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png</span></p>
</div>

<h3>Results</h3>
<div class="doc-section">

<p>The <a href="command-line-options.html#fx">-fx</a> operator evaluates the given expression for each channel (set by <a href="command-line-options.html#channel">-channel</a>) of each pixel in the first image (<kbd>u</kbd>) in the sequence. The computed values are temporarily stored in a copy (clone) of that first image until all the pixels have been processed, after which this single new image replaces the list of images in the current image sequence.  As such, in the previous example the updated version of <kbd>alpha.png</kbd> replaces both of the original images, <kbd>alpha.png</kbd> and <kbd>beta.png</kbd>, before being saved as <kbd>gamma.png</kbd>.</p>

<p>The current image <kbd>s</kbd> is 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> reference the current pixel being processed.</p>


<p>For use with <a href="command-line-options.html#format_identify_">-format</a>, the value-escape <kbd>%[fx: ]</kbd> is evaluated just once for each image in the current image sequence. As each image in the sequence is being evaluated, <kbd>s</kbd> and <kbd>t</kbd> successively refer to the current image and its index, while <kbd>i</kbd> and <kbd>j</kbd> are set to zero, and the current channel set to red (<a href="command-line-options.html#channel">-channel</a> is ignored). An example:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert  canvas:'rgb(25%,50%,75%)' rose: -colorspace rgb  \ <br/>
  -format 'Red channel of NW corner of image #%[fx:t] is %[fx: s]' info:</span><span class='crtout'>Red channel of NW corner of image #0 is 0.453758 <br/>
  Red channel of NW corner of image #1 is 0.184588</span></p>
<p>Here we use the image indexes to <em>rotate</em> each image differently, and use <kbd>-set</kbd> with the image index to set a different <em>pause delay</em> on the first image in the animation:</p>

<p class='crt'><span class="crtprompt"> $ </span><span class='crtin'>convert rose: -duplicate 29 -virtual-pixel Gray -distort SRT '%[fx:360.0*t/n]' \ <br />
    -set delay '%[fx:t == 0 ? 240 : 10]' -loop 0 rose.gif</span></p><p>The color-escape <kbd>%[pixel: ]</kbd> is evaluated once per image and per color channel in that image (<a href="command-line-options.html#channel">-channel</a> is ignored), The values generated are then converted into a color string (a 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> refer to each successively current image and index.</p>

</div>
</div>

</div>

<div id="linkbar">
    <span id="linkbar-west">&nbsp;</span>
    <span id="linkbar-center">
      <a href="../discourse-server">Discourse Server</a> &bull;
      <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi">Studio</a>
    </span>
    <span id="linkbar-east">&nbsp;</span>
  </div>
  <div class="footer">
    <span id="footer-west">&copy; 1999-2012 ImageMagick Studio LLC</span>
    <span id="footer-east"> <a href="contact.html">Contact the Wizards</a></span>
  </div>
  <div style="clear: both; margin: 0; width: 100%; "></div>
  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-17690367-1']);
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>
</body>
</html>