2
0
mirror of https://github.com/boostorg/gil.git synced 2026-02-13 00:22:11 +00:00
Files
gil/develop/doc/html/image_processing/contrast_enhancement/histogram_equalization.html
github-actions[bot] 7dcfd65d45 deploy: caf92fa94b
2022-04-21 14:40:43 +00:00

152 lines
8.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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" />
<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/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" 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>
<div class="section" id="histogram-equalization">
<span id="he"></span><h1>Histogram Equalization</h1>
<div class="section" id="description">
<h2>Description</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>
<div class="align-center figure" 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>
<p class="caption"><span class="caption-text">Pixels concentrated in an interval spread out.</span></p>
</div>
</div>
<div class="section" id="algorithm">
<h2>Algorithm</h2>
<ol class="arabic simple">
<li>First calculate the histogram corresponding to input image.</li>
<li>If it is a multi channeled image (e.g. RGB), convert it to a independent color space
(like YCbCr, HSV etc.).</li>
<li>Then calculate the cumulative histogram over the input image.</li>
<li>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).</li>
<li>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.</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>=&gt; H(p<sub>x</sub>) = H(p<sub>x</sub>)</p>
<p>=&gt; p<sub>x</sub> = H(p<sub>x</sub>)</p>
</div></blockquote>
</div>
<div class="section" id="results">
<h2>Results</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>
<div class="align-center figure">
<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>
</div>
<p><strong>RGB</strong></p>
<div class="align-center figure">
<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>
</div>
</div>
<div class="section" id="demo">
<h2>Demo</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="n">inp_img</span><span class="p">;</span>
<span class="n">read_image</span><span class="p">(</span><span class="s">&quot;your_image.png&quot;</span><span class="p">,</span> <span class="n">inp_img</span><span class="p">,</span> <span class="n">png_tag</span><span class="p">{});</span>
<span class="n">gray8_image_t</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="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">&lt;</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">bool</span><span class="o">&gt;&gt;</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="n">vector</span><span class="o">&lt;</span><span class="kt">bool</span><span class="o">&gt;</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="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="n">view</span><span class="p">(</span><span class="n">dst_img</span><span class="p">),</span> <span class="nb">true</span><span class="p">,</span> <span class="n">mask</span><span class="p">);</span>
</pre></div>
</div>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">Convert an RGB image to a channel independent color space
before trying the histogram equalization algorithm.</p>
</div>
</div></blockquote>
</div>
</div>
<div class="navbar" style="text-align:right;">
</div>
</div>
<div class="footer" role="contentinfo">
Last updated on 2022-04-21 14:04:31.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
</div>
</body>
</html>