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