1 2 3 4 5<!DOCTYPE html> 6<html lang="en"> 7<head> 8 <meta charset="utf-8" /> 9 <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no" /> 10 <title>Command-line Tools: Compare @ ImageMagick</title> 11 <meta name="application-name" content="ImageMagick" /> 12 <meta name="description" content="Use ImageMagick® to create, edit, compose, or convert bitmap images. You can resize your image, crop it, change its shades and colors, add captions, among other operations." /> 13 <meta name="application-url" content="https://imagemagick.org" /> 14 <meta name="generator" content="PHP" /> 15 <meta name="keywords" content="command-line, tools:, compare, 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-2019 ImageMagick Studio LLC" /> 23 <meta name="distribution" content="Global" /> 24 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" /> 25 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> 26 <link href="compare.html" rel="canonical" /> 27 <link href="../images/wand.png" rel="icon" /> 28 <link href="../images/wand.ico" rel="shortcut icon" /> 29 <link href="assets/magick.css" rel="stylesheet" /> 30</head> 31<body> 32 <header> 33 <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> 34 <a class="navbar-brand" href="../"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a> 35 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation"> 36 <span class="navbar-toggler-icon"></span> 37 </button> 38 39 <div class="navbar-collapse collapse" id="navbarsMagick" style=""> 40 <ul class="navbar-nav mr-auto"> 41 <li class="nav-item "> 42 <a class="nav-link" href="api/quantize.html">Home <span class="sr-only">(current)</span></a> 43 </li> 44 <li class="nav-item "> 45 <a class="nav-link" href="../www/download.html">Download</a> 46 </li> 47 <li class="nav-item "> 48 <a class="nav-link" href="../www/command-line-tools.html">Tools</a> 49 </li> 50 <li class="nav-item "> 51 <a class="nav-link" href="../www/command-line-processing.html">Command-line</a> 52 </li> 53 <li class="nav-item "> 54 <a class="nav-link" href="../www/resources.html">Resources</a> 55 </li> 56 <li class="nav-item "> 57 <a class="nav-link" href="../www/develop.html">Develop</a> 58 </li> 59 <li class="nav-item"> 60 <a class="nav-link" target="_blank" href="https://imagemagick.org/discourse-server/">Community</a> 61 </li> 62 </ul> 63 <form class="form-inline my-2 my-lg-0" action="https://imagemagick.org/script/search.php"> 64 <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search"> 65 <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button> 66 </form> 67 </div> 68 </nav> 69 <div class="container"> 70 <script async="async" src="https://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" 71 style="display:block" 72 data-ad-client="ca-pub-3129977114552745" 73 data-ad-slot="6345125851" 74 data-ad-format="auto"></ins> 75 <script> 76 (adsbygoogle = window.adsbygoogle || []).push({}); 77 </script> 78 79 </div> 80 </header> 81 <main class="container"> 82 <div class="magick-template"> 83<div class="magick-header"> 84<p class="text-center"><a href="compare.html#usage">Example Usage</a> • <a href="compare.html#options">Option Summary</a></p> 85 86<p class="lead magick-description">Use the <code>compare</code> program to mathematically and visually annotate the difference between an image and its reconstruction. See <a href="../www/command-line-processing.html">Command Line Processing</a> for advice on how to structure your <code>compare</code> command or see below for example usages of the command.</p> 87 88<h2><a class="anchor" id="usage"></a>Example Usage</h2> 89 90<p>We list a few examples of the <code>compare</code> command here to illustrate its usefulness and ease of use. To get started, lets compare an image to one thats been sharpened:</p> 91 92<pre class="highlight"><code>magick convert rose.jpg -sharpen 0x1 reconstruct.jpg 93magick compare rose.jpg reconstruct.jpg difference.png 94magick compare -compose src rose.jpg reconstruct.jpg difference.png 95</code></pre> 96 97<ul> 98 <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a> 99 <a href="../images/reconstruct.jpg"><img src="../images/reconstruct.jpg" width="70" height="46" alt="rose" /></a> 100 <img style="margin:13px 0;" src="../images/right.gif" width="20" height="20" alt="==>" /> 101 <a href="../images/difference.png"><img src="../images/difference.png" width="70" height="46" alt="rose" /></a> 102</ul> 103 104<p>The red areas of the difference image emphasizes (highlight) pixels that are affected by the image sharpening, whereas white de-emphasizes (lowlight) pixels that are untouched by the sharpening process.</p> 105 106<p>In addition to the visual interpretation of the difference in an image and its reconstruction, we report a mathematical measure of the difference:</p> 107 108<pre class="highlight"><code>-> magick compare -verbose -metric mae rose.jpg reconstruct.jpg difference.png 109Image: rose.jpg 110 Channel distortion: MAE 111 red: 2282.91 (0.034835) 112 green: 1853.99 (0.0282901) 113 blue: 2008.67 (0.0306503) 114 all: 1536.39 (0.0234439) 115</code></pre> 116<p>Or, if you just want the red channel distortion, use this command:</p> 117 118<pre class="highlight"><code>-> magick compare -channel red -metric PSNR rose.jpg reconstruct.jpg difference.png 11919.63 120</code></pre> 121 122<p>Or, if you just want the overall image distortion, use this command:</p> 123 124<pre class="highlight"><code>-> magick compare -metric PSNR rose.jpg reconstruct.jpg difference.png 12528.31 126</code></pre> 127 128<p>If the reconstructed image is a subimage of the image, the compare program returns the best match offset. In addition, it returns a similarity image such that an exact match location is completely white and if none of the pixels match, black, otherwise some gray level in-between:</p> 129 130<pre class="highlight"><code>-> magick compare -metric RMSE -subimage-search logo.png wizard.jpg similarity.gif 13185.05 (0.00129778) @ 353,157 132</code></pre> 133 134<p>You can find additional examples of using <code>compare</code> in <a href="http://www.ibm.com/developerworks/library/l-graf/?ca=dnt-428">Graphics from the Command Line</a>. Further discussion is available in <a href="http://www.ibm.com/developerworks/library/l-graf2/?ca=dgr-lnxw15GraphicsLine">More Graphics from the Command Line</a> and <a href="../Usage/">Examples of ImageMagick Usage</a>.</p> 135 136<p>Two images are considered similar if their difference according to the specified metric and fuzz value is 0, with the exception of the normalized cross correlation metric (NCC), where two images are considered similar when their normalized cross correlation is 1. The default metric is NCC.</p> 137 138<p>The compare program returns 2 on error, 0 if the images are similar, or a value between 0 and 1 if they are not similar.</p> 139 140<h2><a class="anchor" id="options"></a>Option Summary</h2> 141 142<p>The <code>compare</code> command recognizes these options. Click on an option to get more details about how that option works.</p> 143 144<table class="table table-sm table-striped"> 145 <tbody> 146 <tr> 147 <th align="left">Option</th> 148 <th align="left">Description</th> 149 </tr> 150 151 <tr> 152 <td><a href="../www/command-line-options.html#alpha">-alpha</a></td> 153 <td>on, activate, off, deactivate, set, opaque, copy", 154transparent, extract, background, or shape the alpha channel</td> 155 </tr> 156 157 <tr> 158 <td><a href="../www/command-line-options.html#authenticate">-authenticate <var>value</var></a></td> 159 <td>decrypt image with this password</td> 160 </tr> 161 162 <tr> 163 <td><a href="../www/command-line-options.html#background">-background <var>color</var></a></td> 164 <td>background color</td> 165 </tr> 166 167 <tr> 168 <td><a href="../www/command-line-options.html#brightness-contrast">-brightness-contrast <var>geometry</var></a></td> 169 <td>improve brightness / contrast of the image</td> 170 </tr> 171 172 <tr> 173 <td><a href="../www/command-line-options.html#channel">-channel <var>type</var></a></td> 174 <td>apply option to select image channels</td> 175 </tr> 176 177 <tr> 178 <td><a href="../www/command-line-options.html#colorspace">-colorspace <var>type</var></a></td> 179 <td>set image colorspace</td> 180 </tr> 181 182 <tr> 183 <td><a href="../www/command-line-options.html#compose">-compose <var>operator</var></a></td> 184 <td>set image composite operator</td> 185 </tr> 186 187 <tr> 188 <td><a href="../www/command-line-options.html#crop">-crop <var>geometry</var></a></td> 189 <td>crop the image</td> 190 </tr> 191 192 <tr> 193 <td><a href="../www/command-line-options.html#decipher">-decipher <var>filename</var></a></td> 194 <td>convert cipher pixels to plain</td> 195 </tr> 196 197 <tr> 198 <td><a href="../www/command-line-options.html#debug">-debug <var>events</var></a></td> 199 <td>display copious debugging information</td> 200 </tr> 201 202 <tr> 203 <td><a href="../www/command-line-options.html#define">-define <var>format:option</var></a></td> 204 <td>define one or more image format options</td> 205 </tr> 206 207 <tr> 208 <td><a href="../www/command-line-options.html#density">-density <var>geometry</var></a></td> 209 <td>horizontal and vertical density of the image</td> 210 </tr> 211 212 <tr> 213 <td><a href="../www/command-line-options.html#depth">-depth <var>value</var></a></td> 214 <td>image depth</td> 215 </tr> 216 217 <tr> 218 <td><a href="../www/command-line-options.html#dissimilarity-threshold">-dissimilarity-threshold <var>value</var></a></td> 219 <td>maximum distortion for (sub)image match (default 0.2)</td> 220 </tr> 221 222 <tr> 223 <td><a href="../www/command-line-options.html#distort">-distort <var>type coefficients</var></a></td> 224 <td>distort image</td> 225 </tr> 226 227 <tr> 228 <td><a href="../www/command-line-options.html#encipher">-encipher <var>filename</var></a></td> 229 <td>convert plain pixels to cipher pixels</td> 230 </tr> 231 232 <tr> 233 <td><a href="../www/command-line-options.html#extract">-extract <var>geometry</var></a></td> 234 <td>extract area from image</td> 235 </tr> 236 237 <tr> 238 <td><a href="../www/command-line-options.html#fuzz">-fuzz <var>distance</var></a></td> 239 <td>colors within this distance are considered equal</td> 240 </tr> 241 242 <tr> 243 <td><a href="../www/command-line-options.html#gravity">-gravity <var>type</var></a></td> 244 <td>horizontal and vertical text placement</td> 245 </tr> 246 247 <tr> 248 <td><a href="../www/command-line-options.html#help">-help</a></td> 249 <td>print program options</td> 250 </tr> 251 252 <tr> 253 <td><a href="../www/command-line-options.html#highlight-color">-highlight-color <var>color</var></a></td> 254 <td>emphasize pixel differences with this color</td> 255 </tr> 256 257 <tr> 258 <td><a href="../www/command-line-options.html#identify">-identify</a></td> 259 <td>identify the format and characteristics of the image</td> 260 </tr> 261 262 <tr> 263 <td><a href="../www/command-line-options.html#interlace">-interlace <var>type</var></a></td> 264 <td>type of image interlacing scheme</td> 265 </tr> 266 267 <tr> 268 <td><a href="../www/command-line-options.html#level">-level <var>value</var></a></td> 269 <td>adjust the level of image contrast</td> 270 </tr> 271 272 <tr> 273 <td><a href="../www/command-line-options.html#limit">-limit <var>type value</var></a></td> 274 <td>pixel cache resource limit</td> 275 </tr> 276 277 <tr> 278 <td><a href="../www/command-line-options.html#log">-log <var>format</var></a></td> 279 <td>format of debugging information</td> 280 </tr> 281 282 <tr> 283 <td><a href="../www/command-line-options.html#lowlight-color">-lowlight-color <var>color</var></a></td> 284 <td>de-emphasize pixel differences with this color</td> 285 </tr> 286 287 <tr> 288 <td><a href="../www/command-line-options.html#metric">-metric <var>type</var></a></td> 289 <td>measure differences between images with this metric</td> 290 </tr> 291 292 <tr> 293 <td><a href="../www/command-line-options.html#negate">-negate</a></td> 294 <td>replace each pixel with its complementary color </td> 295 </tr> 296 297 <tr> 298 <td><a href="../www/command-line-options.html#profile">-profile <var>filename</var></a></td> 299 <td>add, delete, or apply an image profile</td> 300 </tr> 301 302 <tr> 303 <td><a href="../www/command-line-options.html#quality">-quality <var>value</var></a></td> 304 <td>JPEG/MIFF/PNG compression level</td> 305 </tr> 306 307 <tr> 308 <td><a href="../www/command-line-options.html#quantize">-quantize <var>colorspace</var></a></td> 309 <td>reduce image colors in this colorspace</td> 310 </tr> 311 312 <tr> 313 <td><a href="../www/command-line-options.html#quiet">-quiet</a></td> 314 <td>suppress all warning messages</td> 315 </tr> 316 317 <tr> 318 <td><a href="../www/command-line-options.html#read-mask">-read-mask <var>filename</var></a></td> 319 <td>associate a read mask with the image</td> 320 </tr> 321 322 <tr> 323 <td><a href="../www/command-line-options.html#regard-warnings">-regard-warnings</a></td> 324 <td>pay attention to warning messages.</td> 325 </tr> 326 327 <tr> 328 <td><a href="../www/command-line-options.html#repage">-repage <var>geometry</var></a></td> 329 <td>size and location of an image canvas</td> 330 </tr> 331 332 <tr> 333 <td><a href="../www/command-line-options.html#resize">-resize <var>geometry</var></a></td> 334 <td>resize the image</td> 335 </tr> 336 337 <tr> 338 <td><a href="../www/command-line-options.html#respect-parentheses">-respect-parentheses</a></td> 339 <td>settings remain in effect until parenthesis boundary.</td> 340 </tr> 341 342 <tr> 343 <td><a href="../www/command-line-options.html#rotate">-rotate <var>degrees</var></a></td> 344 <td>apply Paeth rotation to the image</td> 345 </tr> 346 347 <tr> 348 <td><a href="../www/command-line-options.html#sampling-factor">-sampling-factor <var>geometry</var></a></td> 349 <td>horizontal and vertical sampling factor</td> 350 </tr> 351 352 <tr> 353 <td><a href="../www/command-line-options.html#seed">-seed <var>value</var></a></td> 354 <td>seed a new sequence of pseudo-random numbers</td> 355 </tr> 356 357 <tr> 358 <td><a href="../www/command-line-options.html#separate">-separate</a></td> 359 <td>separate an image channel into a grayscale image</td> 360 </tr> 361 362 <tr> 363 <td><a href="../www/command-line-options.html#set">-set <var>attribute value</var></a></td> 364 <td>set an image attribute</td> 365 </tr> 366 367 <tr> 368 <td><a href="../www/command-line-options.html#sigmoidal">-sigmoidal-contrast <var>geometry</var></a></td> 369 <td>increase the contrast without saturating highlights or shadows</td> 370 </tr> 371 372 <tr> 373 <td><a href="../www/command-line-options.html#similarity-threshold">-similarity-threshold <var>value</var></a></td> 374 <td>minimum distortion for (sub)image match (default 0.0)</td> 375 </tr> 376 377 <tr> 378 <td><a href="../www/command-line-options.html#size">-size <var>geometry</var></a></td> 379 <td>width and height of image</td> 380 </tr> 381 382 <tr> 383 <td><a href="../www/command-line-options.html#subimage-search">-subimage-search</a></td> 384 <td>search for subimage</td> 385 </tr> 386 387 <tr> 388 <td><a href="../www/command-line-options.html#synchronize">-synchronize</a></td> 389 <td>synchronize image to storage device</td> 390 </tr> 391 392 <tr> 393 <td><a href="../www/command-line-options.html#taint">-taint</a></td> 394 <td>mark the image as modified</td> 395 </tr> 396 397 <tr> 398 <td><a href="../www/command-line-options.html#transparent-color">-transparent-color <var>color</var></a></td> 399 <td>transparent color</td> 400 </tr> 401 402 <tr> 403 <td><a href="../www/command-line-options.html#trim">-trim</a></td> 404 <td>trim image edges</td> 405 </tr> 406 407 <tr> 408 <td><a href="../www/command-line-options.html#verbose">-verbose</a></td> 409 <td>print detailed information about the image</td> 410 </tr> 411 412 <tr> 413 <td><a href="../www/command-line-options.html#version">-version</a></td> 414 <td>print version information</td> 415 </tr> 416 417 <tr> 418 <td><a href="../www/command-line-options.html#virtual-pixel">-virtual-pixel <var>method</var></a></td> 419 <td>access method for pixels outside the boundaries of the image</td> 420 </tr> 421 422 <tr> 423 <td><a href="../www/command-line-options.html#write-mask">-read-mask <var>filename</var></a></td> 424 <td>associate a write mask with the image</td> 425 </tr> 426 427 </tbody> 428</table> 429</div> 430 </div> 431 </main><!-- /.container --> 432 <footer class="magick-footer"> 433 <p><a href="../www/security-policy.html">Security</a> • 434 <a href="../www/architecture.html">Architecture</a> • 435 <a href="../www/links.html">Related</a> • 436 <a href="../www/sitemap.html">Sitemap</a> 437 438 <a href="compare.html#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../images/wand.ico"/></a> 439 440 <a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • 441 <a href="../www/support.html">Donate</a> • 442 <a href="../www/https://imagemagick.org/script/contact.php">Contact Us</a> 443 <br/> 444 <small>© 1999-2019 ImageMagick Studio LLC</small></p> 445 </footer> 446 447 <!-- Javascript assets --> 448 <script src="assets/magick.js" crossorigin="anonymous"></script> 449 <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.3.1/jquery.min.js"><\/script>')</script> 450</body> 451</html> 452