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, initial-scale=1" /> 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 digital 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, image processing software" /> 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="Create, Edit, Compose, or Convert Digital Images" /> 31 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> 32 <link href="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 bg-dark fixed-top"> 39 <div class="container-fluid"> 40 <a class="navbar-brand" href="../"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a> 41 <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#magick-navbars" aria-controls="magick-navbars" aria-expanded="false" aria-label="Toggle navigation"> 42 <span class="navbar-toggler-icon"></span> 43 </button> 44 45 <div class="collapse navbar-collapse" id="magick-navbars"> 46 <ul class="navbar-nav me-auto mb-2 mb-md-0"> 47 <li class="nav-item"> 48 <a class="nav-link " href="../www/index.html">Home</a> 49 </li> 50 <li class="nav-item"> 51 <a class="nav-link " href="../www/download.html">Download</a> 52 </li> 53 <li class="nav-item"> 54 <a class="nav-link " href="../www/command-line-tools.html">Tools</a> 55 </li> 56 <li class="nav-item"> 57 <a class="nav-link " href="../www/command-line-processing.html">CLI</a> 58 </li> 59 <li class="nav-item"> 60 <a class="nav-link " href="../www/develop.html">Develop</a> 61 </li> 62 <li class="nav-item"> 63 <a class="nav-link" target="_blank" href="https://github.com/ImageMagick/ImageMagick/discussions">Community</a> 64 </li> 65 <li class="nav-item"> 66 <iframe src="https://github.com/sponsors/ImageMagick/button" title="Sponsor ImageMagick" height="35" width="107" style="border: 0;"></iframe> 67 </li> 68 </ul> 69 <form class="d-flex form-inline" action="search.html"> 70 <input class="form-control me-2" type="text" name="q" placeholder="Search" aria-label="Search"> 71 <button class="btn btn-outline-success" type="submit" name="sa">Search</button> 72 </form> 73 </div> 74 </div> 75 </nav> 76 77 <div class="container"> 78 <script async="async" src="https://localhost/pagead/js/adsbygoogle.js"></script> 79 <ins class="adsbygoogle" 80 style="display:block" 81 data-ad-client="ca-pub-3129977114552745" 82 data-ad-slot="6345125851" 83 data-full-width-responsive="true" 84 data-ad-format="horizontal"></ins> 85 <script> 86 (adsbygoogle = window.adsbygoogle || []).push({}); 87 </script> 88 89 </div> 90 91 <main class="container"> 92 <div class="magick-template"> 93<div class="magick-header"> 94<h1 class="text-center">Image Simularity Comparison</h1> 95<p class="text-center"><a href="compare.html#usage">Example Usage</a> • <a href="compare.html#options">Option Summary</a></p> 96 97<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> 98 99<h2><a class="anchor" id="usage"></a>Example Usage</h2> 100 101<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> 102 103<pre class="highlight"><code>magick rose.jpg -sharpen 0x1 reconstruct.jpg 104magick compare rose.jpg reconstruct.jpg difference.png 105magick compare -compose src rose.jpg reconstruct.jpg difference.png 106</code></pre> 107 108<ul> 109 <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a> 110 <a href="../images/reconstruct.jpg"><img src="../images/reconstruct.jpg" width="70" height="46" alt="rose" /></a> 111 <img style="margin:13px 0;" src="../images/right.gif" width="20" height="20" alt="==>" /> 112 <a href="../images/difference.png"><img src="../images/difference.png" width="70" height="46" alt="rose" /></a> 113</ul> 114 115<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> 116 117<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> 118 119<pre class="highlight"><code>-> magick compare -verbose -metric mae rose.jpg reconstruct.jpg difference.png 120Image: rose.jpg 121 Channel distortion: MAE 122 red: 2282.91 (0.034835) 123 green: 1853.99 (0.0282901) 124 blue: 2008.67 (0.0306503) 125 all: 1536.39 (0.0234439) 126</code></pre> 127<p>Or, if you just want the red channel distortion, use this command:</p> 128 129<pre class="highlight"><code>-> magick compare -channel red -metric PSNR rose.jpg reconstruct.jpg difference.png 13019.63 131</code></pre> 132 133<p>Or, if you just want the overall image distortion, use this command:</p> 134 135<pre class="highlight"><code>-> magick compare -metric PSNR rose.jpg reconstruct.jpg difference.png 13628.31 137</code></pre> 138 139<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> 140 141<pre class="highlight"><code>-> magick compare -metric RMSE -subimage-search logo.png wizard.jpg similarity.gif 14285.05 (0.00129778) @ 353,157 143</code></pre> 144 145<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="https://legacy.imagemagick.org/Usage/">Examples of ImageMagick Usage</a>.</p> 146 147<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> 148 149<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> 150 151<h2><a class="anchor" id="options"></a>Option Summary</h2> 152 153<p>The <code>compare</code> command recognizes these options. Click on an option to get more details about how that option works.</p> 154 155<table class="table table-sm table-hover"> 156 <tbody> 157 <tr> 158 <th align="left">Option</th> 159 <th align="left">Description</th> 160 </tr> 161 162 <tr> 163 <td><a href="../www/command-line-options.html#alpha">-alpha</a></td> 164 <td>on, activate, off, deactivate, set, opaque, copy", 165transparent, extract, background, or shape the alpha channel</td> 166 </tr> 167 168 <tr> 169 <td><a href="../www/command-line-options.html#authenticate">-authenticate <var>value</var></a></td> 170 <td>decrypt image with this password</td> 171 </tr> 172 173 <tr> 174 <td><a href="../www/command-line-options.html#background">-background <var>color</var></a></td> 175 <td>background color</td> 176 </tr> 177 178 <tr> 179 <td><a href="../www/command-line-options.html#brightness-contrast">-brightness-contrast <var>geometry</var></a></td> 180 <td>improve brightness / contrast of the image</td> 181 </tr> 182 183 <tr> 184 <td><a href="../www/command-line-options.html#channel">-channel <var>type</var></a></td> 185 <td>apply option to select image channels</td> 186 </tr> 187 188 <tr> 189 <td><a href="../www/command-line-options.html#colorspace">-colorspace <var>type</var></a></td> 190 <td>set image colorspace</td> 191 </tr> 192 193 <tr> 194 <td><a href="../www/command-line-options.html#compose">-compose <var>operator</var></a></td> 195 <td>set image composite operator</td> 196 </tr> 197 198 <tr> 199 <td><a href="../www/command-line-options.html#crop">-crop <var>geometry</var></a></td> 200 <td>crop the image</td> 201 </tr> 202 203 <tr> 204 <td><a href="../www/command-line-options.html#decipher">-decipher <var>filename</var></a></td> 205 <td>convert cipher pixels to plain</td> 206 </tr> 207 208 <tr> 209 <td><a href="../www/command-line-options.html#debug">-debug <var>events</var></a></td> 210 <td>display copious debugging information</td> 211 </tr> 212 213 <tr> 214 <td><a href="../www/command-line-options.html#define">-define <var>format:option</var></a></td> 215 <td>define one or more image format options</td> 216 </tr> 217 218 <tr> 219 <td><a href="../www/command-line-options.html#density">-density <var>geometry</var></a></td> 220 <td>horizontal and vertical density of the image</td> 221 </tr> 222 223 <tr> 224 <td><a href="../www/command-line-options.html#depth">-depth <var>value</var></a></td> 225 <td>image depth</td> 226 </tr> 227 228 <tr> 229 <td><a href="../www/command-line-options.html#dissimilarity-threshold">-dissimilarity-threshold <var>value</var></a></td> 230 <td>maximum distortion for (sub)image match (default 0.2)</td> 231 </tr> 232 233 <tr> 234 <td><a href="../www/command-line-options.html#distort">-distort <var>type coefficients</var></a></td> 235 <td>distort image</td> 236 </tr> 237 238 <tr> 239 <td><a href="../www/command-line-options.html#encipher">-encipher <var>filename</var></a></td> 240 <td>convert plain pixels to cipher pixels</td> 241 </tr> 242 243 <tr> 244 <td><a href="../www/command-line-options.html#extract">-extract <var>geometry</var></a></td> 245 <td>extract area from image</td> 246 </tr> 247 248 <tr> 249 <td><a href="../www/command-line-options.html#fuzz">-fuzz <var>distance</var></a></td> 250 <td>colors within this distance are considered equal</td> 251 </tr> 252 253 <tr> 254 <td><a href="../www/command-line-options.html#gravity">-gravity <var>type</var></a></td> 255 <td>horizontal and vertical text placement</td> 256 </tr> 257 258 <tr> 259 <td><a href="../www/command-line-options.html#help">-help</a></td> 260 <td>print program options</td> 261 </tr> 262 263 <tr> 264 <td><a href="../www/command-line-options.html#highlight-color">-highlight-color <var>color</var></a></td> 265 <td>emphasize pixel differences with this color</td> 266 </tr> 267 268 <tr> 269 <td><a href="../www/command-line-options.html#identify">-identify</a></td> 270 <td>identify the format and characteristics of the image</td> 271 </tr> 272 273 <tr> 274 <td><a href="../www/command-line-options.html#interlace">-interlace <var>type</var></a></td> 275 <td>type of image interlacing scheme</td> 276 </tr> 277 278 <tr> 279 <td><a href="../www/command-line-options.html#level">-level <var>value</var></a></td> 280 <td>adjust the level of image contrast</td> 281 </tr> 282 283 <tr> 284 <td><a href="../www/command-line-options.html#limit">-limit <var>type value</var></a></td> 285 <td>pixel cache resource limit</td> 286 </tr> 287 288 <tr> 289 <td><a href="../www/command-line-options.html#log">-log <var>format</var></a></td> 290 <td>format of debugging information</td> 291 </tr> 292 293 <tr> 294 <td><a href="../www/command-line-options.html#lowlight-color">-lowlight-color <var>color</var></a></td> 295 <td>de-emphasize pixel differences with this color</td> 296 </tr> 297 298 <tr> 299 <td><a href="../www/command-line-options.html#metric">-metric <var>type</var></a></td> 300 <td>measure differences between images with this metric</td> 301 </tr> 302 303 <tr> 304 <td><a href="../www/command-line-options.html#negate">-negate</a></td> 305 <td>replace each pixel with its complementary color </td> 306 </tr> 307 308 <tr> 309 <td><a href="../www/command-line-options.html#profile">-profile <var>filename</var></a></td> 310 <td>add, delete, or apply an image profile</td> 311 </tr> 312 313 <tr> 314 <td><a href="../www/command-line-options.html#quality">-quality <var>value</var></a></td> 315 <td>JPEG/MIFF/PNG compression level</td> 316 </tr> 317 318 <tr> 319 <td><a href="../www/command-line-options.html#quantize">-quantize <var>colorspace</var></a></td> 320 <td>reduce image colors in this colorspace</td> 321 </tr> 322 323 <tr> 324 <td><a href="../www/command-line-options.html#quiet">-quiet</a></td> 325 <td>suppress all warning messages</td> 326 </tr> 327 328 <tr> 329 <td><a href="../www/command-line-options.html#read-mask">-read-mask <var>filename</var></a></td> 330 <td>associate a read mask with the image</td> 331 </tr> 332 333 <tr> 334 <td><a href="../www/command-line-options.html#regard-warnings">-regard-warnings</a></td> 335 <td>pay attention to warning messages.</td> 336 </tr> 337 338 <tr> 339 <td><a href="../www/command-line-options.html#repage">-repage <var>geometry</var></a></td> 340 <td>size and location of an image canvas</td> 341 </tr> 342 343 <tr> 344 <td><a href="../www/command-line-options.html#resize">-resize <var>geometry</var></a></td> 345 <td>resize the image</td> 346 </tr> 347 348 <tr> 349 <td><a href="../www/command-line-options.html#respect-parentheses">-respect-parentheses</a></td> 350 <td>settings remain in effect until parenthesis boundary.</td> 351 </tr> 352 353 <tr> 354 <td><a href="../www/command-line-options.html#rotate">-rotate <var>degrees</var></a></td> 355 <td>apply Paeth rotation to the image</td> 356 </tr> 357 358 <tr> 359 <td><a href="../www/command-line-options.html#sampling-factor">-sampling-factor <var>geometry</var></a></td> 360 <td>horizontal and vertical sampling factor</td> 361 </tr> 362 363 <tr> 364 <td><a href="../www/command-line-options.html#seed">-seed <var>value</var></a></td> 365 <td>seed a new sequence of pseudo-random numbers</td> 366 </tr> 367 368 <tr> 369 <td><a href="../www/command-line-options.html#separate">-separate</a></td> 370 <td>separate an image channel into a grayscale image</td> 371 </tr> 372 373 <tr> 374 <td><a href="../www/command-line-options.html#set">-set <var>attribute value</var></a></td> 375 <td>set an image attribute</td> 376 </tr> 377 378 <tr> 379 <td><a href="../www/command-line-options.html#sigmoidal">-sigmoidal-contrast <var>geometry</var></a></td> 380 <td>increase the contrast without saturating highlights or shadows</td> 381 </tr> 382 383 <tr> 384 <td><a href="../www/command-line-options.html#similarity-threshold">-similarity-threshold <var>value</var></a></td> 385 <td>minimum distortion for (sub)image match (default 0.0)</td> 386 </tr> 387 388 <tr> 389 <td><a href="../www/command-line-options.html#size">-size <var>geometry</var></a></td> 390 <td>width and height of image</td> 391 </tr> 392 393 <tr> 394 <td><a href="../www/command-line-options.html#subimage-search">-subimage-search</a></td> 395 <td>search for subimage</td> 396 </tr> 397 398 <tr> 399 <td><a href="../www/command-line-options.html#synchronize">-synchronize</a></td> 400 <td>synchronize image to storage device</td> 401 </tr> 402 403 <tr> 404 <td><a href="../www/command-line-options.html#taint">-taint</a></td> 405 <td>mark the image as modified</td> 406 </tr> 407 408 <tr> 409 <td><a href="../www/command-line-options.html#transparent-color">-transparent-color <var>color</var></a></td> 410 <td>transparent color</td> 411 </tr> 412 413 <tr> 414 <td><a href="../www/command-line-options.html#trim">-trim</a></td> 415 <td>trim image edges</td> 416 </tr> 417 418 <tr> 419 <td><a href="../www/command-line-options.html#verbose">-verbose</a></td> 420 <td>print detailed information about the image</td> 421 </tr> 422 423 <tr> 424 <td><a href="../www/command-line-options.html#version">-version</a></td> 425 <td>print version information</td> 426 </tr> 427 428 <tr> 429 <td><a href="../www/command-line-options.html#virtual-pixel">-virtual-pixel <var>method</var></a></td> 430 <td>access method for pixels outside the boundaries of the image</td> 431 </tr> 432 433 <tr> 434 <td><a href="../www/command-line-options.html#write-mask">-read-mask <var>filename</var></a></td> 435 <td>associate a write mask with the image</td> 436 </tr> 437 438 </tbody> 439</table> 440</div> 441 </div> 442 </main><!-- /.container --> 443 <footer class="magick-footer"> 444 <div class="container-fluid"> 445 <a href="../www/security-policy.html">Security</a> • 446 <a href="../www/news.html">News</a> 447 448 <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> 449 450 <a href="../www/links.html">Related</a> • 451 <a href="../www/sitemap.html">Sitemap</a> 452 <br/> 453 <a href="../www/support.html">Sponsor</a> • 454 <a href="../www/cite.html">Cite</a> • 455 <a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • 456 <a href="../www/https://imagemagick.org/script/contact.php">Contact Us</a> 457 <br/> 458 <a href="https://github.com/imagemagick/imagemagick" target="_blank" rel="noopener" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 512 499.36" width="2%" height="2%" role="img" focusable="false"><title>GitHub</title><path fill="currentColor" fill-rule="evenodd" d="M256 0C114.64 0 0 114.61 0 256c0 113.09 73.34 209 175.08 242.9 12.8 2.35 17.47-5.56 17.47-12.34 0-6.08-.22-22.18-.35-43.54-71.2 15.49-86.2-34.34-86.2-34.34-11.64-29.57-28.42-37.45-28.42-37.45-23.27-15.84 1.73-15.55 1.73-15.55 25.69 1.81 39.21 26.38 39.21 26.38 22.84 39.12 59.92 27.82 74.5 21.27 2.33-16.54 8.94-27.82 16.25-34.22-56.84-6.43-116.6-28.43-116.6-126.49 0-27.95 10-50.8 26.35-68.69-2.63-6.48-11.42-32.5 2.51-67.75 0 0 21.49-6.88 70.4 26.24a242.65 242.65 0 0 1 128.18 0c48.87-33.13 70.33-26.24 70.33-26.24 14 35.25 5.18 61.27 2.55 67.75 16.41 17.9 26.31 40.75 26.31 68.69 0 98.35-59.85 120-116.88 126.32 9.19 7.9 17.38 23.53 17.38 47.41 0 34.22-.31 61.83-.31 70.23 0 6.85 4.61 14.81 17.6 12.31C438.72 464.97 512 369.08 512 256.02 512 114.62 397.37 0 256 0z"/></svg></a> • 459 <a href="https://twitter.com/imagemagick" target="_blank" rel="noopener" aria-label="Twitter"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 512 416.32" width="2%" height="2%" role="img" focusable="false"><title>Twitter</title><path fill="currentColor" d="M160.83 416.32c193.2 0 298.92-160.22 298.92-298.92 0-4.51 0-9-.2-13.52A214 214 0 0 0 512 49.38a212.93 212.93 0 0 1-60.44 16.6 105.7 105.7 0 0 0 46.3-58.19 209 209 0 0 1-66.79 25.37 105.09 105.09 0 0 0-181.73 71.91 116.12 116.12 0 0 0 2.66 24c-87.28-4.3-164.73-46.3-216.56-109.82A105.48 105.48 0 0 0 68 159.6a106.27 106.27 0 0 1-47.53-13.11v1.43a105.28 105.28 0 0 0 84.21 103.06 105.67 105.67 0 0 1-47.33 1.84 105.06 105.06 0 0 0 98.14 72.94A210.72 210.72 0 0 1 25 370.84a202.17 202.17 0 0 1-25-1.43 298.85 298.85 0 0 0 160.83 46.92"/></svg></a> 460 <br/> 461 <small>© 1999-2021 ImageMagick Studio LLC</small> 462 </div> 463 </footer> 464 465 <!-- Javascript assets --> 466 <script src="assets/magick.js" ></script> 467 </body> 468</html> 469<!-- Magick Cache 13th February 2021 11:42 -->