mirror of
https://github.com/boostorg/gil.git
synced 2026-02-13 12:32:09 +00:00
156 lines
8.9 KiB
HTML
156 lines
8.9 KiB
HTML
|
||
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
||
<title>Histogram Equalization - Boost.GIL documentation</title>
|
||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/style.css" type="text/css" />
|
||
<script type="text/javascript">
|
||
var DOCUMENTATION_OPTIONS = {
|
||
URL_ROOT: '../../',
|
||
VERSION: '',
|
||
COLLAPSE_MODINDEX: false,
|
||
FILE_SUFFIX: '.html'
|
||
};
|
||
</script>
|
||
<script type="text/javascript" src="../../_static/documentation_options.js"></script>
|
||
<script type="text/javascript" src="../../_static/doctools.js"></script>
|
||
<script type="text/javascript" src="../../_static/sphinx_highlight.js"></script>
|
||
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
|
||
<script src="../../_static/searchtools.js"></script>
|
||
<script src="../../_static/language_data.js"></script>
|
||
<link rel="index" title="Index" href="../../genindex.html" />
|
||
<link rel="search" title="Search" href="../../search.html" />
|
||
<link rel="top" title="Boost.GIL documentation" href="../../index.html" />
|
||
</head>
|
||
<body>
|
||
<div class="header">
|
||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||
"header">
|
||
<tr>
|
||
<td valign="top" width="300">
|
||
<h3><a href="../../index.html"><img
|
||
alt="C++ Boost" src="../../../../_static/gil.png" border="0"></a></h3>
|
||
</td>
|
||
<td >
|
||
<h1 align="center"><a href="../../index.html"></a></h1>
|
||
</td>
|
||
<td>
|
||
<div id="searchbox" style="display: none">
|
||
<form class="search" action="../../search.html" method="get">
|
||
<input type="text" name="q" size="18" />
|
||
<input type="submit" value="Search" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<hr/>
|
||
<div class="content">
|
||
<div class="navbar" style="text-align:right;">
|
||
|
||
|
||
|
||
</div>
|
||
|
||
<section id="histogram-equalization">
|
||
<span id="he"></span><h1>Histogram Equalization<a class="headerlink" href="#histogram-equalization" title="Link to this heading">¶</a></h1>
|
||
<section id="description">
|
||
<h2>Description<a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
|
||
<p>Histogram equalization also known as histogram flattening, is a non-linear image enhancement
|
||
algorithm that follows the idea that not only should an image cover the entire grayscale space
|
||
but also be uniformly distributed over that range.</p>
|
||
<p>An ideal image would be the one having a flat histogram.</p>
|
||
<p>Although care should be taken before applying a non-linear transformation on the image
|
||
histogram, there are good mathematical reasons why a flat histogram is the desired goal.</p>
|
||
<p>A simple scenario would be an image with pixels concentrated in an interval, in which case
|
||
histogram equalization transforms pixels to achieve a flat histogram image. Thus enhancing
|
||
the image contrast.</p>
|
||
<figure class="align-center" id="id1">
|
||
<a class="reference internal image-reference" href="image_processing/contrast_enhancement/he_chart.png"><img alt="Could not load image." src="image_processing/contrast_enhancement/he_chart.png" style="width: 200px; height: 100px;" /></a>
|
||
<figcaption>
|
||
<p><span class="caption-text">Pixels concentrated in an interval spread out.</span><a class="headerlink" href="#id1" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</section>
|
||
<section id="algorithm">
|
||
<h2>Algorithm<a class="headerlink" href="#algorithm" title="Link to this heading">¶</a></h2>
|
||
<ol class="arabic simple">
|
||
<li><p>First calculate the histogram corresponding to input image.</p></li>
|
||
<li><p>If it is a multi channeled image (e.g. RGB), convert it to a independent color space
|
||
(like YCbCr, HSV etc.).</p></li>
|
||
<li><p>Then calculate the cumulative histogram over the input image.</p></li>
|
||
<li><p>Normalize the histogram to bring bin values between 0-1. For multi-channeled images
|
||
normalize each channel independently (by the number of pixels in image).</p></li>
|
||
<li><p>If the histogram of image is H(p<sub>x</sub>) p<sub>x</sub> in [0, 255], then apply
|
||
the transformation p<sub>x’</sub> = H(p<sub>x</sub>), p<sub>x’</sub> is pixel in output
|
||
image.</p></li>
|
||
</ol>
|
||
<p><strong>Explanation</strong></p>
|
||
<p>Since we will be transforming the image to match a flat histogram, we match
|
||
the cumulative histogram of the image to the cumulative histogram of a flat histogram.</p>
|
||
<p>Cumulative histogram of flat image is H(p<sub>x’</sub>) = p<sub>x’</sub> .</p>
|
||
<p>Hence,</p>
|
||
<blockquote>
|
||
<div><p>=> H(p<sub>x’</sub>) = H(p<sub>x</sub>)</p>
|
||
<p>=> p<sub>x’</sub> = H(p<sub>x</sub>)</p>
|
||
</div></blockquote>
|
||
</section>
|
||
<section id="results">
|
||
<h2>Results<a class="headerlink" href="#results" title="Link to this heading">¶</a></h2>
|
||
<p>The algorithm is applied on a few standard images. One of the transformations in shown below:</p>
|
||
<p><strong>Grayscale Image</strong></p>
|
||
<figure class="align-center">
|
||
<a class="reference internal image-reference" href="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/barbara.jpg"><img alt="Could not load image." src="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/barbara.jpg" style="width: 512px; height: 256px;" /></a>
|
||
</figure>
|
||
<p><strong>RGB</strong></p>
|
||
<figure class="align-center">
|
||
<a class="reference internal image-reference" href="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/church.jpg"><img alt="Could not load image." src="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/church.jpg" style="width: 900px; height: 300px;" /></a>
|
||
</figure>
|
||
</section>
|
||
<section id="demo">
|
||
<h2>Demo<a class="headerlink" href="#demo" title="Link to this heading">¶</a></h2>
|
||
<p>Usage Syntax:</p>
|
||
<blockquote>
|
||
<div><div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">gray8_image_t</span><span class="w"> </span><span class="n">inp_img</span><span class="p">;</span>
|
||
<span class="n">read_image</span><span class="p">(</span><span class="s">"your_image.png"</span><span class="p">,</span><span class="w"> </span><span class="n">inp_img</span><span class="p">,</span><span class="w"> </span><span class="n">png_tag</span><span class="p">{});</span>
|
||
<span class="n">gray8_image_t</span><span class="w"> </span><span class="nf">dst_img</span><span class="p">(</span><span class="n">inp_img</span><span class="p">.</span><span class="n">dimensions</span><span class="p">());</span>
|
||
<span class="n">histogram_equalization</span><span class="p">(</span><span class="n">view</span><span class="p">(</span><span class="n">inp_img</span><span class="p">),</span><span class="w"> </span><span class="n">view</span><span class="p">(</span><span class="n">dst_img</span><span class="p">));</span>
|
||
|
||
<span class="c1">// To specify mask over input image</span>
|
||
|
||
<span class="n">vector</span><span class="o"><</span><span class="n">vector</span><span class="o"><</span><span class="kt">bool</span><span class="o">>></span><span class="w"> </span><span class="n">mask</span><span class="p">(</span><span class="n">inp_img</span><span class="p">.</span><span class="n">height</span><span class="p">(),</span><span class="w"> </span><span class="n">vector</span><span class="o"><</span><span class="kt">bool</span><span class="o">></span><span class="p">(</span><span class="n">inp_img</span><span class="p">.</span><span class="n">width</span><span class="p">(),</span><span class="w"> </span><span class="nb">true</span><span class="p">));</span>
|
||
<span class="n">histogram_equalization</span><span class="p">(</span><span class="n">view</span><span class="p">(</span><span class="n">inp_img</span><span class="p">),</span><span class="w"> </span><span class="n">view</span><span class="p">(</span><span class="n">dst_img</span><span class="p">),</span><span class="w"> </span><span class="nb">true</span><span class="p">,</span><span class="w"> </span><span class="n">mask</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition tip">
|
||
<p class="admonition-title">Tip</p>
|
||
<p>Convert an RGB image to a channel independent color space
|
||
before trying the histogram equalization algorithm.</p>
|
||
</div>
|
||
</div></blockquote>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="navbar" style="text-align:right;">
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
Last updated on 2026-02-06 18:02:17.
|
||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 7.2.6.
|
||
</div>
|
||
</body>
|
||
</html> |