• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 - Contrast Limited Adaptive Histogram Equalization</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="contrast, limited, adaptive, histogram, equalization, 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/www/clahe.html" rel="canonical" />
33  <link href="../www/images/wand.png" rel="icon" />
34  <link href="../www/images/wand.ico" rel="shortcut icon" />
35  <link href="../www/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="../www/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="../www/index.html">Home <span class="sr-only">(current)</span></a>
48      </li>
49      <li class="nav-item ">
50        <a class="nav-link" href="../www/www/download.html">Download</a>
51      </li>
52      <li class="nav-item ">
53        <a class="nav-link" href="../www/www/command-line-tools.html">Tools</a>
54      </li>
55      <li class="nav-item ">
56        <a class="nav-link" href="../www/www/command-line-processing.html">Command-line</a>
57      </li>
58      <li class="nav-item ">
59        <a class="nav-link" href="../www/www/resources.html">Resources</a>
60      </li>
61      <li class="nav-item ">
62        <a class="nav-link" href="../www/www/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="../www/www/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="lead magick-description">Use Adaptive histogram equalization (AHE) to improve contrast in images.  Ordinary histogram equalization computes a global equalization whereas an adaptive method computes several histograms, each corresponding to a distinct section of the image, and uses them to redistribute the lightness values of the image.  It is suitable for improving the local contrast and enhancing the definitions of edges in each region of an image.  A variant of adaptive histogram equalization, contrast limited adaptive histogram equalization (CLAHE) limits AHE's tendency to overamplify noise in relatively homogeneous regions of an image.</p>
91<p>CLAHE is supported as of ImageMagick 7.0.8-24 with the <a href="../www/www/command-line-options.html#clahe">-clahe</a> option:</p>
92<ul>
93<h6><a class="anchor" id="clahe"></a>-clahe <var>width</var>x<var>height</var>{%}{+}<var>number-bins</var>{+}<var>clip-limit</var>{!}</h6>
94</ul>
95<p> The image is divided into tiles of <var>width</var> and <var>height</var> pixels.  Append <code>%</code> to define the width and height as percentages of the image's dimensions. The tile size should be larger than the size of features to be preserved and respects the aspect ratio of the image.  Add <code>!</code> to force an exact tile width and height. <var>number-bins</var> is the number of histogram bins per tile (min 2, max 65536).  The number of histogram bins should be smaller than the number of pixels in a single tile. <var>clip-limit</var> is the contrast limit for localized changes in contrast. A clip-limit of 2 to 3 is a good starting place (e.g. -clahe 50x50%+128+3).  Very large values will let the histogram equalization do whatever it wants to do, that is result in maximal local contrast. The value 1 will result in the original image.  Note, if the number of bins and the clip-limit are omitted, they default to 128 and no clipping respectively.</p>
96<p>To visualize the benefits of CLAHE, we have a low contrast image of mountains:</p>
97<p>
98<ul>
99  <a href="../www/images/mountains.jpg"><img src="../www/images/mountains.jpg" width="500" height="333" alt="label" /></a>
100</ul>
101<p>We can improve the image with global histogram equalization:</p>
102<ul>
103  <a href="../www/images/mountains.jpg"><img src="../www/images/mountains-equalize.jpg" width="500" height="333" alt="label" /></a>
104</ul>
105<p>We can further improve the image with the contrast limited adaptive histogram equalization image processing technique:</p>
106<ul>
107  <a href="../www/images/mountains.jpg"><img src="../www/images/mountains-clahe.jpg" width="500" height="333" alt="label" /></a>
108</ul>
109<p>The latter image was produced with this command:</p>
110<pre class="highlight">
111magick mountains.jpg -clahe 25x25%+128+3 mountains-clahe.jpg
112</pre>
113<p>The <code>25x25%</code> argument divides the image into 16 tiles to perform local contrast enhancement.  The image dimensions are <code>1500x1000</code> so the tiles are exactly <code>375x250</code> pixels each.  Rather than a percentage, you can specify the tile dimensions directly with <code>375x250</code>.</p>
114<p>For tile sizes that do not divide evenly into the image dimensions, CLAHE utilizes virtual pixels, as such the results can vary slightly based on your chosen virtual pixel method.  For example,</p>
115<pre class="highlight">
116magick mountains.jpg -virtual-pixel mirror -clahe 300x300+128+3! mountains-clahe.jpg
117</pre>
118<p>Notice the <code>!</code>.  That forces the tile size to exactly 300x300 pixels, whereas without the <code>!</code>, the tile size respects the aspect ratio of the image and results in tile dimensions of <code>300x200</code>.</p>
119
120</div>
121    </div>
122  </main><!-- /.container -->
123  <footer class="magick-footer">
124    <p><a href="../www/www/security-policy.html">Security</a> •
125    <a href="../www/www/architecture.html">Architecture</a>
126
127    <a href="clahe.html#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../www/images/wand.ico"/></a>
128
129    <a href="../www/www/links.html">Related</a> •
130     <a href="../www/www/sitemap.html">Sitemap</a>
131    <br/>
132    <a href="../www/www/support.html">Donate</a> •
133    <a href="http://pgp.mit.edu/pks/lookup?op=get&amp;search=0x89AB63D48277377A">Public Key</a> •
134    <a href="../www/www/https://imagemagick.org/script/contact.php">Contact Us</a>
135    <br/>
136    <small>© 1999-2020 ImageMagick Studio LLC</small></p>
137  </footer>
138
139  <!-- Javascript assets -->
140  <script src="../www/assets/magick.js" crossorigin="anonymous"></script>
141  <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.4.1/jquery.min.js"><\/script>')</script>
142</body>
143</html>
144<!-- Magick Cache 5th January 2020 12:07 -->