Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 1 | |
| 2 | |
| 3 | |
| 4 | |
cristy | 29dc865 | 2015-05-12 16:26:21 +0000 | [diff] [blame] | 5 | <!DOCTYPE html> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 6 | <html lang="en"> |
cristy | ad41c0c | 2012-10-31 00:49:28 +0000 | [diff] [blame] | 7 | <head> |
Cristy | bbb6988 | 2017-06-30 10:13:32 -0400 | [diff] [blame] | 8 | <meta charset="utf-8" /> |
| 9 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> |
Cristy | 6549abb | 2016-11-10 08:25:55 -0500 | [diff] [blame] | 10 | <title>The Fx Special Effects Image Operator @ ImageMagick</title> |
Cristy | bbb6988 | 2017-06-30 10:13:32 -0400 | [diff] [blame] | 11 | <meta name="application-name" content="ImageMagick" /> |
| 12 | <meta name="description" content="ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, JPEG-2000, GIF, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves." /> |
| 13 | <meta name="application-url" content="https://www.imagemagick.org" /> |
| 14 | <meta name="generator" content="PHP" /> |
| 15 | <meta name="keywords" content="the, fx, special, effects, image, operator, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert" /> |
| 16 | <meta name="rating" content="GENERAL" /> |
| 17 | <meta name="robots" content="INDEX, FOLLOW" /> |
| 18 | <meta name="generator" content="ImageMagick Studio LLC" /> |
| 19 | <meta name="author" content="ImageMagick Studio LLC" /> |
| 20 | <meta name="revisit-after" content="2 DAYS" /> |
| 21 | <meta name="resource-type" content="document" /> |
| 22 | <meta name="copyright" content="Copyright (c) 1999-2017 ImageMagick Studio LLC" /> |
| 23 | <meta name="distribution" content="Global" /> |
| 24 | <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" /> |
Cristy | 912a922 | 2016-06-17 15:37:28 -0400 | [diff] [blame] | 25 | <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> |
Cristy | bbb6988 | 2017-06-30 10:13:32 -0400 | [diff] [blame] | 26 | <link href="https://www.imagemagick.org/script/fx.html" rel="canonical" /> |
| 27 | <link href="../images/wand.png" rel="icon" /> |
| 28 | <link href="../images/wand.ico" rel="shortcut icon" /> |
| 29 | <link href="css/magick.css" rel="stylesheet" /> |
cristy | ad41c0c | 2012-10-31 00:49:28 +0000 | [diff] [blame] | 30 | </head> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 31 | <body> |
Cristy | bbb6988 | 2017-06-30 10:13:32 -0400 | [diff] [blame] | 32 | <div class="magick-masthead"> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 33 | <div class="container"> |
Cristy | 6549abb | 2016-11-10 08:25:55 -0500 | [diff] [blame] | 34 | <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 35 | style="display:block" |
| 36 | data-ad-client="ca-pub-3129977114552745" |
| 37 | data-ad-slot="6345125851" |
| 38 | data-ad-format="auto"></ins> |
cristy | 29f2c97 | 2015-07-28 13:37:46 +0000 | [diff] [blame] | 39 | <script> |
Cristy | 542697a | 2015-10-12 20:10:32 -0400 | [diff] [blame] | 40 | (adsbygoogle = window.adsbygoogle || []).push({}); |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 41 | </script> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 42 | <nav class="nav magick-nav"> |
| 43 | <a class="nav-link " href="../index.html">Home</a> |
| 44 | <a class="nav-link " href="download.html">Download</a> |
| 45 | <a class="nav-link " href="command-line-tools.html">Tools</a> |
| 46 | <a class="nav-link " href="command-line-processing.html">Command-line</a> |
| 47 | <a class="nav-link " href="resources.html">Resources</a> |
| 48 | <a class="nav-link " href="develop.html">Develop</a> |
| 49 | <a class="nav-link " href="https://www.imagemagick.org/script/search.php">Search</a> |
| 50 | <a class="nav-link float-right" href="https://www.imagemagick.org/discourse-server/">Community</a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 51 | </nav> |
| 52 | </div> |
| 53 | </div> |
| 54 | <div class="container"> |
| 55 | <div class="magick-header"> |
| 56 | <p class="text-center"><a href="fx.html#fx">The Fx Special Effects Image Operator</a> • <a href="fx.html#anatomy">The Anatomy of an Fx Expression</a></p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 57 | |
cristy | dcca3fa | 2010-12-29 21:50:07 +0000 | [diff] [blame] | 58 | <a id="fx"></a> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 59 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 60 | <p class="lead magick-description">Use the Fx special effects image operator to apply a mathematical expression to an image or image channels. Use Fx to:</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 61 | |
| 62 | <ul> |
| 63 | <li>create canvases, gradients, mathematical colormaps</li> |
| 64 | <li>move color values between images and channels</li> |
| 65 | <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li> |
| 66 | <li>merge or composite multiple images together</li> |
| 67 | <li>convolve or merge neighboring pixels together</li> |
| 68 | <li>generate image metrics or 'fingerprints'</li> |
| 69 | </ul> |
| 70 | |
| 71 | <p>The expression can be simple:</p> |
| 72 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 73 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 74 | convert -size 64x64 canvas:black -channel blue -fx "1/2" fx_navy.png |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 75 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 76 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 77 | <p>Here, we convert a black to a navy blue image:</p> |
| 78 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 79 | <ul> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 80 | <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" alt="black" /></a> |
| 81 | <img style="margin-top:22px; margin-bottom:22px;" src="../images/right.gif" width="20" height="20" alt="==>" /> |
| 82 | <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" alt="navy" /></a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 83 | </ul> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 84 | |
| 85 | <p>Or the expression can be complex:</p> |
| 86 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 87 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 88 | convert rose.jpg \ |
| 89 | -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \ |
| 90 | rose-sigmoidal.png' |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 91 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 92 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 93 | <p>This expression results in a high contrast version of the image:</p> |
| 94 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 95 | <ul> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 96 | <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a> |
| 97 | <img style="margin-top:13px; margin-bottom:13px;" src="../images/right.gif" width="20" height="20" alt="==>" /> |
| 98 | <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 99 | </ul> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 100 | |
| 101 | <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> |
| 102 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 103 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 104 | convert -size 70x70 canvas: \ |
cristy | a1890f0 | 2015-05-15 23:32:44 +0000 | [diff] [blame] | 105 | -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" |
| 106 | radial-gradient.png' |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 107 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 108 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | <p>The command above returns this image:</p> |
| 110 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 111 | <ul> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 112 | <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 113 | </ul> |
cristy | e9a32c3 | 2011-04-07 01:11:05 +0000 | [diff] [blame] | 114 | |
| 115 | <p>This FX expression adds random noise to an image:</p> |
| 116 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 117 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 118 | convert photo.jpg -fx \'iso=32; rone=rand(); rtwo=rand(); \ |
| 119 | myn=sqrt(-2*ln(rone))*cos(2*Pi*rtwo); myntwo=sqrt(-2*ln(rtwo))* \ |
| 120 | cos(2*Pi*rone); pnoise=sqrt(p)*myn*sqrt(iso)* \ |
| 121 | channel(4.28,3.86,6.68,0)/255; max(0,p+pnoise)\' noisy.png |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 122 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 123 | |
Cristy | 364a72f | 2016-11-04 22:38:41 -0400 | [diff] [blame] | 124 | <p>See <a href="https://www.imagemagick.org/Usage/transform/index.html#fx">Using FX, The Special Effects Image Operator</a> for more examples.</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | |
| 126 | <p>The next section discusses the Fx expression language.</p> |
| 127 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 128 | <h2 class="magick-post-title"><a id="anatomy"></a>The Anatomy of an Fx Expression</h2> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 129 | |
| 130 | <h3>The Fx Expression Language</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | |
| 132 | <p>The formal Fx expression language is defined here:</p> |
| 133 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 134 | <dl class="row"> |
| 135 | <dt class="col-md-4"> numbers:</dt> |
| 136 | <dd class="col-md-8"> integer, floating point, scientific notation (+/- required, e.g. 3.81469e-06), International System number postfixes (.e.g KB, Mib, GB, etc.)</dd> |
| 137 | <dt class="col-md-4"> constants: </dt> |
| 138 | <dd class="col-md-8"> E (Euler's number), Epsilon, QuantumRange, QuantumScale, Opaque, Phi (golden ratio), Pi, Transparent</dd> |
| 139 | <dt class="col-md-4"> Fx operators (in order of precedence): </dt> |
| 140 | <dd class="col-md-8"> ^ (power), unary -, *, /, % (modulo), +, -, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | <<, >>, <, <=, >, >=, ==, !=, |
| 142 | & (bitwise AND), | (bitwise OR), |
| 143 | && (logical AND), || (logical OR), |
| 144 | ~ (logical NOT), ?: (ternary conditional)</dd> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 145 | <dt class="col-md-4"> math functions: </dt> |
| 146 | <dd class="col-md-8"> abs(), acos(), acosh(), airy(), alt(), asin(), asinh(), atan(), atanh(), atan2(), ceil(), clamp(), cos(), cosh(), debug(), drc(), erf(), 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> |
| 147 | <dt class="col-md-4"> channel functions: </dt> |
| 148 | <dd class="col-md-8"> channel(r,g,b,a), channel(c,m,y,k,a)</dd> |
| 149 | <dt class="col-md-4"> color names:</dt> |
| 150 | <dd class="col-md-8"> red, cyan, black, etc.</dd> |
| 151 | <dt class="col-md-4"> color functions:</dt> |
| 152 | <dd class="col-md-8"> srgb(), srgba(), rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla(), etc.</dd> |
| 153 | <dt class="col-md-4"> color hex values:</dt> |
| 154 | <dd class="col-md-8"> #ccc, #cbfed0, #b9e1cc00, etc.</dd> |
| 155 | <dt class="col-md-4"> symbols:</dt><dd class="col-md-8"><dl> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 156 | <li><code>u</code>=> first image in list</li> |
| 157 | <li><code>v</code>=> second image in list</li> |
| 158 | <li><code>s</code>=> current image in list (for %[fx:] otherwise = u)</li> |
| 159 | <li><code>t</code>=> index of current image (s) in list</li> |
| 160 | <li><code>n</code>=> number of images in list</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 162 | <li><code>i</code>=> column offset</li> |
| 163 | <li><code>j</code>=> row offset</li> |
| 164 | <li><code>p</code>=> pixel to use (absolute or relative to current pixel)</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 166 | <li><code>w</code>=> width of this image</li> |
| 167 | <li><code>h</code>=> height of this image</li> |
| 168 | <li><code>z</code>=> channel depth</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 170 | <li><code>r</code>=> red value (from RGBA), of a specific or current pixel</li> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 171 | <li><code>g</code>=> green</li> |
| 172 | <li><code>b</code>=> blue</li> |
| 173 | <li><code>a</code>=> alpha</li> |
| 174 | <li><code>o</code>=> opacity</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 176 | <li><code>c</code>=> cyan value of CMYK color of pixel</li> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 177 | <li><code>y</code>=> yellow</li> |
| 178 | <li><code>m</code>=> magenta</li> |
| 179 | <li><code>k</code>=> black</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 181 | <li><code>intensity</code>=> pixel intensity</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 183 | <li><code>hue</code>=> pixel hue</li> |
| 184 | <li><code>saturation</code>=> pixel saturation</li> |
| 185 | <li><code>lightness</code>=> pixel lightness</li> |
| 186 | <li><code>luma</code>=> pixel luma</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 187 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 188 | <li><code>page.width</code>=> page width</li> |
| 189 | <li><code>page.height</code>=> page height</li> |
| 190 | <li><code>page.x</code>=> page x offset</li> |
| 191 | <li><code>page.y</code>=> page y offset</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 192 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 193 | <li><code>resolution.x</code>=> x resolution</li> |
| 194 | <li><code>resolution.y</code>=> y resolution</li> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 196 | <li><code>depth</code>=> image depth</li> |
| 197 | <li><code>minima</code>=> image minima</li> |
| 198 | <li><code>maxima</code>=> image maxima</li> |
| 199 | <li><code>mean</code>=> image mean</li> |
| 200 | <li><code>standard_deviation</code>=> image standard deviation</li> |
| 201 | <li><code>kurtosis</code>=> image kurtosis</li> |
| 202 | <li><code>skewness</code>=> image skewness (add a channel specifier to compute a statistic for that channel, e.g. depth.r)</li></dl></dd> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 203 | <dt class="col-md-4"> iterators:</dt> |
| 204 | <dd class="col-md-8"> while()</dd> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 205 | </dl> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 207 | |
| 208 | <h3>The Fx Expression</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | |
| 210 | <p>An Fx expression may include any combination of the following:</p> |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 211 | <dl class="row"> |
| 212 | <dt class="col-md-4"> <var>x</var> <code>^</code> <var>y</var></dt><dd class="col-md-8"> exponentiation (<var>x<sup>y</sup></var>)</dd> |
| 213 | <dt class="col-md-4"> <code>(</code> ... <code>)</code></dt><dd class="col-md-8"> grouping</dd> |
| 214 | <dt class="col-md-4"> <var>x</var> <code>*</code> <var>y</var></dt><dd class="col-md-8"> multiplication (the asterisk <code>*</code> is optional, for example, <code>2u</code> or <code>2(x+y)</code> are acceptable)</dd> |
| 215 | <dt class="col-md-4"> <var>x</var> <code>/</code> <var>y</var></dt><dd class="col-md-8"> division</dd> |
| 216 | <dt class="col-md-4"> <var>x</var> <code>%</code> <var>y</var></dt><dd class="col-md-8"> modulo</dd> |
| 217 | <dt class="col-md-4"> <var>x</var> <code>+</code> <var>y</var></dt><dd class="col-md-8"> addition</dd> |
| 218 | <dt class="col-md-4"> <var>x</var> <code>-</code> <var>y</var></dt><dd class="col-md-8"> subtraction</dd> |
| 219 | <dt class="col-md-4"> <var>x</var> <code><<</code> <var>y</var></dt><dd class="col-md-8"> left shift</dd> |
| 220 | <dt class="col-md-4"> <var>x</var> <code>>></code> <var>y</var></dt><dd class="col-md-8"> right shift</dd> |
| 221 | <dt class="col-md-4"> <var>x</var> <code><</code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> < <var>y</var>, otherwise 0.0</dd> |
| 222 | <dt class="col-md-4"> <var>x</var> <code><=</code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> <= <var>y</var>, otherwise 0.0</dd> |
| 223 | <dt class="col-md-4"> <var>x</var> <code>></code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> > <var>y</var>, otherwise 0.0</dd> |
| 224 | <dt class="col-md-4"> <var>x</var> <code>>=</code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> >= <var>y</var>, otherwise 0.0</dd> |
| 225 | <dt class="col-md-4"> <var>x</var> <code>==</code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x </var>==<var> y</var>, otherwise 0.0</dd> |
| 226 | <dt class="col-md-4"> <var>x</var> <code>!=</code> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x </var>!=<var> y</var>, otherwise 0.0</dd> |
| 227 | <dt class="col-md-4"> <var>x</var> <code>&</code> <var>y</var></dt><dd class="col-md-8"> binary AND</dd> |
| 228 | <dt class="col-md-4"> <var>x</var> <code>|</code> <var>y</var></dt><dd class="col-md-8"> binary OR</dd> |
| 229 | <dt class="col-md-4"> <var>x</var> <code>&&</code> <var>y</var></dt><dd class="col-md-8"> logical AND connective, return value 1.0 if <var>x</var> > 0 and <var>y</var> > 0, otherwise 0.0</dd> |
| 230 | <dt class="col-md-4"> <var>x</var> <code>||</code> <var>y</var></dt><dd class="col-md-8"> logical OR connective (inclusive), return value 1.0 if <var>x</var> > 0 or <var>y</var> > 0 (or both), otherwise 0.0</dd> |
| 231 | <dt class="col-md-4"> <code>~</code><var>x</var></dt><dd class="col-md-8"> logical NOT operator, return value 1.0 if <var>not</var> <var>x</var> > 0, otherwise 0.0</dd> |
| 232 | <dt class="col-md-4"> <code>+</code><var>x</var></dt><dd class="col-md-8"> unary plus, return 1.0*value</dd> |
| 233 | <dt class="col-md-4"> <code>-</code><var>x</var></dt><dd class="col-md-8"> unary minus, return -1.0*value</dd> |
| 234 | <dt class="col-md-4"> <var>x</var> <code>?</code> <var>y</var> <code>:</code> <var>z</var> </dt><dd class="col-md-8">ternary conditional expression, return value <var>y</var> if <var>x</var> != 0, otherwise <var>z</var>; only one ternary conditional permitted per statement</dd> |
| 235 | <dt class="col-md-4"> <var>x</var> <code>=</code> <var>y</var></dt><dd class="col-md-8">assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</dd> |
| 236 | <dt class="col-md-4"> <var>x</var> <code>;</code> <var>y</var></dt><dd class="col-md-8">statement separator </dd> |
| 237 | <dt class="col-md-4"> <code>phi</code></dt><dd class="col-md-8"> constant (1.618034...)</dd> |
| 238 | <dt class="col-md-4"> <code>pi</code></dt><dd class="col-md-8"> constant (3.14159265359...)</dd> |
| 239 | <dt class="col-md-4"> <code>e</code></dt><dd class="col-md-8"> constant (2.71828...)</dd> |
| 240 | <dt class="col-md-4"> <code>QuantumRange</code></dt><dd class="col-md-8"> constant maximum pixel value (255 for Q8, 65535 for Q16)</dd> |
| 241 | <dt class="col-md-4"> <code>QuantumScale</code></dt><dd class="col-md-8"> constant 1.0/<code>QuantumRange</code></dd> |
| 242 | <dt class="col-md-4"> <code>intensity</code></dt><dd class="col-md-8"> pixel intensity whose value respects the <a href="command-line-options.html#intensity">-intensity</a> option.</dd> |
| 243 | <dt class="col-md-4"> <code>hue</code></dt><dd class="col-md-8"> pixel hue</dd> |
| 244 | <dt class="col-md-4"> <code>saturation</code></dt><dd class="col-md-8"> pixel saturation</dd> |
| 245 | <dt class="col-md-4"> <code>lightness</code></dt><dd class="col-md-8"> pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</dd> |
| 246 | <dt class="col-md-4"> <code>luminance</code></dt><dd class="col-md-8"> pixel luminance; equivalent to <code>0.212656*red + 0.715158*green + 0.072186*blue</code></dd> |
| 247 | <dt class="col-md-4"> <code>red, green, blue</code>, etc.</dt><dd class="col-md-8"> color names</dd> |
| 248 | <dt class="col-md-4"> <code>#ccc, #cbfed0, #b9e1cc00</code>, etc.</dt><dd class="col-md-8"> color hex values</dd> |
| 249 | <dt class="col-md-4"> <code>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</code></dt><dd class="col-md-8"> color functions</dd> |
| 250 | <dt class="col-md-4"> <code>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</code></dt><dd class="col-md-8"> symbols</dd> |
| 251 | <dt class="col-md-4"> <code>abs(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> absolute value function</dd> |
| 252 | <dt class="col-md-4"> <code>acos(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> arc cosine function</dd> |
| 253 | <dt class="col-md-4"> <code>acosh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> inverse hyperbolic cosine function</dd> |
| 254 | <dt class="col-md-4"> <code>airy(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> Airy function (max=1, min=0); airy(<var>x</var>)=[jinc(<var>x</var>)]<sup>2</sup>=[2*j1(<var>pi*x</var>)/(<var>pi*x</var>)]<sup>2</sup></dd> |
| 255 | <dt class="col-md-4"> <code>alt(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> sign alternation function (return 1.0 if int(<var>x</var>) is even, -1.0 if int(<var>x</var>) is odd)</dd> |
| 256 | <dt class="col-md-4"> <code>asin(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> arc sine function</dd> |
| 257 | <dt class="col-md-4"> <code>asinh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> inverse hyperbolic sine function</dd> |
| 258 | <dt class="col-md-4"> <code>atan(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> arc tangent function</dd> |
| 259 | <dt class="col-md-4"> <code>atanh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> inverse hyperbolic tangent function</dd> |
| 260 | <dt class="col-md-4"> <code>atan2(</code><var>x</var>,<var>y</var><code>)</code></dt><dd class="col-md-8"> arc tangent function of two variables</dd> |
| 261 | <dt class="col-md-4"> <code>ceil(</code><var>x</var><code>)</code></dt><dd class="col-md-8">smallest integral value not less than argument</dd> |
| 262 | <dt class="col-md-4"> <code>channel(</code><var>r</var>,<var>g</var>,<var>b</var>,<var>a</var><code>)</code></dt><dd class="col-md-8">select numeric argument based on current channel</dd> |
| 263 | <dt class="col-md-4"> <code>channel(</code><var>c</var>,<var>m</var>,<var>y</var>,<var>k</var>,<var>a</var><code>)</code></dt><dd class="col-md-8">select numeric argument based on current channel</dd> |
| 264 | <dt class="col-md-4"> <code>clamp(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> clamp value</dd> |
| 265 | <dt class="col-md-4"> <code>cos(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> cosine function</dd> |
| 266 | <dt class="col-md-4"> <code>cosh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> hyperbolic cosine function</dd> |
| 267 | <dt class="col-md-4"> <code>debug(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> print <var>x</var> (useful for debugging your expression)</dd> |
| 268 | <dt class="col-md-4"> <code>drc(</code><var>x</var>,<var>y</var><code>)</code></dt><dd class="col-md-8"> dynamic range compression (knee curve); drc(<var>x</var>,<var>y</var>)=(<var>x</var>)/(<var>y</var>*(<var>x</var>-1)+1); -1<<var>y</var><1 </dd> |
| 269 | <dt class="col-md-4"> <code>erf(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> error function</dd> |
| 270 | <dt class="col-md-4"> <code>exp(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> natural exponential function (<var>e<sup>x</sup></var>)</dd> |
| 271 | <dt class="col-md-4"> <code>floor(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> largest integral value not greater than argument</dd> |
| 272 | <dt class="col-md-4"> <code>gauss(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> gaussian function; gauss(<var>x</var>)=exp(<var>-x*x/2</var>)/sqrt(2*pi)</dd> |
| 273 | <dt class="col-md-4"> <code>gcd(</code><var>x</var>,<var>y</var><code>)</code></dt><dd class="col-md-8"> greatest common denominator</dd> |
| 274 | <dt class="col-md-4"> <code>hypot(</code><var>x</var>,<var>y</var><code>)</code></dt><dd class="col-md-8"> the square root of x<sup>2</sup>+y<sup>2</sup></dd> |
| 275 | <dt class="col-md-4"> <code>int(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> greatest integer function (return greatest integer less than or equal to <var>x</var>)</dd> |
| 276 | <dt class="col-md-4"> <code>isnan(</code><var>x</var><code>)</code></dt><dd class="col-md-8">return 1.0 if <var>x</var> is NAN, 0.0 otherwise</dd> |
| 277 | <dt class="col-md-4"> <code>j0(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> Bessel functions of <var>x</var> of the first kind of order 0</dd> |
| 278 | <dt class="col-md-4"> <code>j1(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> Bessel functions of <var>x</var> of the first kind of order 1</dd> |
| 279 | <dt class="col-md-4"> <code>jinc(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> jinc function (max=1, min=-0.1323); jinc(<var>x</var>)=2*j1(pi*<var>x</var>)/(pi*<var>*x</var>)</dd> |
| 280 | <dt class="col-md-4"> <code>ln(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> natural logarithm function</dd> |
| 281 | <dt class="col-md-4"> <code>log(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> logarithm base 10</dd> |
| 282 | <dt class="col-md-4"> <code>logtwo(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> logarithm base 2</dd> |
| 283 | <dt class="col-md-4"> <code>ln(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> natural logarithm</dd> |
| 284 | <dt class="col-md-4"> <code>max(</code><var>x</var>, <var>y</var><code>)</code></dt><dd class="col-md-8"> maximum of <var>x</var> and <var>y</var></dd> |
| 285 | <dt class="col-md-4"> <code>min(</code><var>x</var>, <var>y</var><code>)</code></dt><dd class="col-md-8"> minimum of <var>x</var> and <var>y</var></dd> |
| 286 | <dt class="col-md-4"> <code>mod(</code><var>x</var>, <var>y</var><code>)</code></dt><dd class="col-md-8"> floating-point remainder function</dd> |
| 287 | <dt class="col-md-4"> <code>not(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> return 1.0 if <var>x</var> is zero, 0.0 otherwise</dd> |
| 288 | <dt class="col-md-4"> <code>pow(</code><var>x</var>,<var>y</var><code>)</code></dt><dd class="col-md-8"> power function (<var>x<sup>y</sup></var>)</dd> |
| 289 | <dt class="col-md-4"> <code>rand()</code></dt><dd class="col-md-8"> value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</dd> |
| 290 | <dt class="col-md-4"> <code>round()</code></dt><dd class="col-md-8"> round to integral value, regardless of rounding direction</dd> |
| 291 | <dt class="col-md-4"> <code>sign(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> return -1.0 if <var>x</var> is less than 0.0 otherwise 1.0</dd> |
| 292 | <dt class="col-md-4"> <code>sin(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> sine function</dd> |
| 293 | <dt class="col-md-4"> <code>sinc(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> sinc function (max=1, min=-0.21); sinc(<var>x</var>)=sin(<var>pi*x</var>)/(<var>pi*x</var>)</dd> |
| 294 | <dt class="col-md-4"> <code>squish(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> squish function; squish(<var>x</var>)=1.0/(1.0+exp(<var>-x</var>))</dd> |
| 295 | <dt class="col-md-4"> <code>sinh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> hyperbolic sine function</dd> |
| 296 | <dt class="col-md-4"> <code>sqrt(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> square root function</dd> |
| 297 | <dt class="col-md-4"> <code>tan(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> tangent function</dd> |
| 298 | <dt class="col-md-4"> <code>tanh(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> hyperbolic tangent function</dd> |
| 299 | <dt class="col-md-4"> <code>trunc(</code><var>x</var><code>)</code></dt><dd class="col-md-8"> round to integer, towards zero</dd> |
| 300 | <dt class="col-md-4"> <code>while(</code><var>condition</var>,<var>expression</var><code>)</code></dt><dd class="col-md-8"> iterate while the condition is not equal to 0</dd> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 301 | </dl> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 302 | <br/> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | <p>The expression semantics include these rules:</p> |
| 304 | |
| 305 | <ul> |
| 306 | <li>symbols are case insensitive</li> |
| 307 | <li>only one ternary conditional (e.g. x ? y : z) per statement</li> |
| 308 | <li>statements are assignments or the final expression to return</li> |
| 309 | <li>an assignment starts a statement, it is not an operator</li> |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 310 | <li>assignments to built-ins do not throw an exception and have no effect; e.g. <code>r=3.0; r</code> returns the pixel red color value, not 3.0</li> |
cristy | b7b531e | 2010-10-24 01:41:05 +0000 | [diff] [blame] | 311 | <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> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 312 | <li>Similarly, care must be exercised when using the slash ('/') symbol. The string of characters <var>1/2x</var> 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> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | </ul> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 314 | <br/> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 315 | |
cristy | ce66ab1 | 2010-10-21 23:36:32 +0000 | [diff] [blame] | 316 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | <h3>Source Images</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 318 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 319 | <p>The symbols <code>u</code> and <code>v</code> 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 <code>u</code>), with a zero index for the beginning of the sequence. A negative index counts from the end. For example, <code>u[0]</code> is the first image in the sequence, <code>u[2]</code> is the third, <code>u[-1]</code> is the last image, and <code>u[t]</code> is the current image. The current image can also be referenced by <code>s</code>. If the sequence number exceeds the length of the sequence, the count is wrapped. Thus in a 3-image sequence, <code>u[-1]</code>, <code>u[2]</code>, and <code>u[5]</code> all refer to the same (third) image.</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 320 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 321 | <p>As an example, we form an image by averaging the first image and third images (the second (index 1) image is ignored and just junked):</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 323 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 324 | convert image1.jpg image2.jpg image3.jpg -fx "(u+u[2])/2.0" image.jpg |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 325 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 326 | |
Cristy | 542697a | 2015-10-12 20:10:32 -0400 | [diff] [blame] | 327 | <p>By default, the image to which <code>p</code>, <code>r</code>, <code>g</code>, <code>b</code>, <code>a</code>, etc., are applied is the current image <code>s</code> in the image list. This is equivalent to <code>u</code> except when used in an escape sequence <code>%[fx:...]</code>. </p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | |
cristy | 751980d | 2012-06-03 23:18:35 +0000 | [diff] [blame] | 329 | <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> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 331 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 332 | convert -channel red logo: -flop logo: -resize "20%" -fx "(u+v)/2" image.jpg |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 333 | </code></pre> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 335 | <ul> |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 336 | <a href="../images/logo-sm-flop.png"><img src="../images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a> |
| 337 | <a href="../images/logo-sm.png"><img src="../images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a> |
| 338 | <img style="margin-top:38px; margin-bottom:38px;" src="../images/right.gif" width="20" height="20" alt="==>" /> |
| 339 | <a href="../images/logo-sm-fx.png"><img src="../images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 340 | </ul> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 341 | |
Cristy | 594d277 | 2015-11-15 10:47:42 -0500 | [diff] [blame] | 342 | <br/> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 343 | <h3>Accessing Pixels</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | |
| 345 | <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> |
| 346 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 347 | <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 <code>p</code>. For example,</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 348 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 349 | <pre><code> |
cristy | a1890f0 | 2015-05-15 23:32:44 +0000 | [diff] [blame] | 350 | p[-1].g green value of pixel to the immediate left of the current pixel |
| 351 | p[-1,-1].r red value of the pixel diagonally left and up from current pixel |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 352 | </code></pre> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | |
| 354 | <p>To specify an absolute position, use braces, rather than brackets.</p> |
| 355 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 356 | <pre><code> |
cristy | a1890f0 | 2015-05-15 23:32:44 +0000 | [diff] [blame] | 357 | p{0,0}.r red value of the pixel in the upper left corner of the image |
| 358 | p{12,34}.b blue pixel value at column number 12, row 34 of the image |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 359 | </code></pre> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 360 | |
cristy | 751980d | 2012-06-03 23:18:35 +0000 | [diff] [blame] | 361 | <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> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | |
cristy | 751980d | 2012-06-03 23:18:35 +0000 | [diff] [blame] | 363 | <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> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 364 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | <h3>Apply an Expression to Select Image Channels</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 366 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 367 | <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 <code>alpha.png</code> with the average of the green channels from the images <code>alpha.png</code> and <code>beta.png</code>, use:</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 369 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 370 | convert alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 371 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 372 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 373 | |
| 374 | <h3>Results</h3> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 376 | <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 (<code>u</code>) 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 <code>alpha.png</code> replaces both of the original images, <code>alpha.png</code> and <code>beta.png</code>, before being saved as <code>gamma.png</code>.</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | |
cristy | 8ee7f24 | 2013-06-20 16:08:44 +0000 | [diff] [blame] | 378 | <p>The current image <code>s</code> is set to the first image in the sequence (<code>u</code>), and <code>t</code> to its index, 0. The symbols <code>i</code> and <code>j</code> reference the current pixel being processed.</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | |
| 380 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 381 | <p>For use with <a href="command-line-options.html#format_identify_">-format</a>, the value-escape <code>%[fx:]</code> is evaluated just once for each image in the current image sequence. As each image in the sequence is being evaluated, <code>s</code> and <code>t</code> successively refer to the current image and its index, while <code>i</code> and <code>j</code> 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> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 383 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 384 | convert canvas:'rgb(25%,50%,75%)' rose: -colorspace rgb \ |
| 385 | -format 'Red channel of NW corner of image #%[fx:t] is %[fx:s]' info: |
| 386 | Red channel of NW corner of image #0 is 0.453758 |
| 387 | Red channel of NW corner of image #1 is 0.184588 |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 388 | </code></pre> |
cristy | 3cd7cc9 | 2011-04-01 01:00:28 +0000 | [diff] [blame] | 389 | |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 390 | <p>Here we use the image indexes to <var>rotate</var> each image differently, and use <code>-set</code> with the image index to set a different <var>pause delay</var> on the first image in the animation:</p> |
| 391 | |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 392 | <pre><code> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 393 | convert rose: -duplicate 29 -virtual-pixel Gray -distort SRT '%[fx:360.0*t/n]' \ |
| 394 | -set delay '%[fx:t == 0 ? 240 : 10]' -loop 0 rose.gif" |
Cristy | 4938040 | 2017-06-29 11:24:55 -0400 | [diff] [blame] | 395 | </code></pre> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 396 | |
Cristy | d07f4fe | 2017-06-02 20:36:40 -0400 | [diff] [blame] | 397 | <p>The color-escape <code>%[pixel:]</code> or <code>%[hex:]</code> 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 <code>i</code> and <code>j</code> are set to zero, and <code>s</code> and <code>t</code> refer to each successively current image and index.</p> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 398 | |
| 399 | </div> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 400 | <footer class="magick-footer"> |
cristy | 29f2c97 | 2015-07-28 13:37:46 +0000 | [diff] [blame] | 401 | <p><a href="support.html">Donate</a> • |
| 402 | <a href="sitemap.html">Sitemap</a> • |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 403 | <a href="links.html">Related</a> • |
Cristy | e077971 | 2016-07-30 17:25:22 -0400 | [diff] [blame] | 404 | <a href="security-policy.html">Security</a> • |
cristy | 29f2c97 | 2015-07-28 13:37:46 +0000 | [diff] [blame] | 405 | <a href="architecture.html">Architecture</a> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 406 | </p> |
| 407 | <p><a href="fx.html#">Back to top</a> • |
cristy | ea2793e | 2015-05-31 16:52:26 +0000 | [diff] [blame] | 408 | <a href="http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • |
Cristy | 6549abb | 2016-11-10 08:25:55 -0500 | [diff] [blame] | 409 | <a href="https://www.imagemagick.org/script/contact.php">Contact Us</a></p> |
Cristy | fe36f99 | 2016-12-29 20:24:13 -0500 | [diff] [blame] | 410 | <p><small>© 1999-2017 ImageMagick Studio LLC</small></p> |
cristy | d243201 | 2015-05-04 23:15:15 +0000 | [diff] [blame] | 411 | </footer> |
| 412 | </div><!-- /.container --> |
cristy | ad41c0c | 2012-10-31 00:49:28 +0000 | [diff] [blame] | 413 | |
Cristy | b7f455a | 2017-03-03 19:30:34 -0500 | [diff] [blame] | 414 | <script src="https://localhost/ajax/libs/jquery/1.12.4/jquery.min.js"></script> |
Cristy | 1f1f3a0 | 2016-06-01 07:25:42 -0400 | [diff] [blame] | 415 | <script src="../js/magick.html"></script> |
cristy | ad41c0c | 2012-10-31 00:49:28 +0000 | [diff] [blame] | 416 | </body> |
cristy | 5a367e4 | 2015-05-05 12:39:18 +0000 | [diff] [blame] | 417 | </html> |