2
0
mirror of https://github.com/boostorg/gil.git synced 2026-02-18 02:02:09 +00:00
Files
gil/develop/doc/html/image_processing/contrast_enhancement/histogram_matching.html
github-actions[bot] be7d3c17b9 deploy: f839504f20
2022-05-13 12:14:30 +00:00

145 lines
7.9 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 Matching - 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-matching">
<span id="hm"></span><h1>Histogram Matching</h1>
<div class="section" id="description">
<h2>Description</h2>
<p>Histogram Matching is a technique to match the histograms of two images.</p>
<p>One use case of this would be when two images of the same location have been taken
under the same local illumination but with different sensors, bringing out different
features in either image.</p>
<p>The famous histogram equalization is a special case of this algorithm when the reference image
is expected to have a uniform histogram.</p>
</div>
<div class="section" id="algorithm">
<h2>Algorithm</h2>
<ol class="arabic simple">
<li>Calculate the histogram corresponding to input image and reference image.</li>
<li>If it is a multi channeled image (e.g. RGB), convert both to an independent color space
(like YCbCr, HSV etc.).</li>
<li>Then calculate the cumulative histogram over the input image and reference image.</li>
<li>Normalize both 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 cumulative histogram of input image is H(p<sub>x</sub>) and of reference image is R(p<sub>x</sub>)
p<sub>x</sub> &amp; p<sub>x</sub> in [0, 255], then apply the transformation
p<sub>x</sub> = R<sup>-1</sup>(H(p<sub>x</sub>))</li>
</ol>
<p><strong>Explanation</strong></p>
<p>Since we will be transforming the image to match a reference image, we match
the cumulative histogram of the image to the cumulative histogram of the reference histogram.</p>
<p>Hence,</p>
<blockquote>
<div><p>=&gt; R(p<sub>x</sub>) = H(p<sub>x</sub>)</p>
<p>=&gt; p<sub>x</sub> = R<sup>-1</sup>(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>Original Image(left) &amp; Reference Image(right)</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/matching.jpg"><img alt="Could not load image." src="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/matching.jpg" style="width: 600px; height: 300px;" /></a>
</div>
<p><strong>Histogram matched 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/matching_out.jpg"><img alt="Could not load image." src="https://github.com/boost-gil/test-images/blob/master/jpeg/suite/matching_out.jpg" style="width: 300px; 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">ref_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">read_image</span><span class="p">(</span><span class="s">&quot;your_ref_image.png&quot;</span><span class="p">,</span> <span class="n">ref_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_matching</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">ref_image</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_matching</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">ref_image</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 matching 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-05-13 12:05:18.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
</div>
</body>
</html>