【转载】HDR图像显示

<div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
                    <div class="markdown_views">
                <h1 id="高动态范围图像"><a name="t0"></a>高动态范围图像</h1>

<p>(High-Dynamic Range,简称HDR),相比普通的图像,可以提供更多的动态范围和图像细节,根据不同的曝光时间的LDR(Low-Dynamic Range)图像,利用每个曝光时间相对应最佳细节的LDR图像来合成最终HDR图像。 <br>
</p><center><img src="https://img-blog.csdn.net/20150501155252980" alt="点击看大图" title="原图" height="150"></center><p></p>

<h1 id="tone-mapping"><a name="t1"></a>tone mapping</h1>

<p>一张HDR图片,它记录了远远超出256个级别的实际场景的亮度值,超出的部分在屏幕上是显示不出来的。所以线性解码,总是导致图像一部分区域过于明亮,或者另一部分过于暗淡。 <br>
</p><center><img src="https://img-blog.csdn.net/20150501160610001" alt="点击看大图" title="tone mapping" height="180"></center> <br>
解决的方法就是tone mapping。这里我们将图像分解为两个层,一个基层(base layer or large-scale features)和一个细节层(detail layer)。只对基层进行对比度压缩,保持细节层不变。这里为将图像分解成两层,且保持边缘特性,就需要采取一些快速健壮的保边去噪的滤波器。比如说双边滤波(BF)等。<p></p>



<h1 id="算法流程"><a name="t2"></a>算法流程</h1>

<p>根据<a href="http://people.csail.mit.edu/fredo/PUBLI/Siggraph2002/" rel="nofollow" target="_blank">《Fast Bilateral Filtering for the Display of High-Dynamic-Range Images 》</a>给出了对比度缩减的流程:</p>

<ol>
<li>input intensity= 1/61*(R*20+G*40+B)</li>
<li>r=R/(input intensity), g=G/input intensity, B=B/input intensity</li>
<li>log(base)=Bilateral(log(input intensity)) </li>
<li>log(detail)=log(input intensity)-log(base)</li>
<li>log (output intensity)=log(base)*compressionfactor+log(detail) - log_absolute_scale</li>
<li>R output = r*10^(log(output intensity)), etc. </li>
</ol>

<p>注:第一步是将原图像转换成其灰度图像,你可以使用其他你喜欢的转换公式。compressionfactor是对基层的压缩系数,log_absolute_scale是一个偏置参数,以确保基层压缩后最大像素值为1,这两个参数都与图像相关。这里作者建议取值 <br>
 compressionfactor = targetContrast/(max(log(base)) - min(log(base))),log_absolute_scale= max(log(base))*compressionfactor。</p>

<p></p><center><img src="https://img-blog.csdn.net/20150501165906477" alt="点击看大图" title="算法流程图" height="420"></center><p></p>



<h1 id="代码"><a name="t3"></a>代码</h1>

<p>通常算法最后还要进行gamma校正,示例如下,edge preserving  fliter你可以换成其他:</p>



<pre class="prettyprint" name="code"><code class="hljs oxygene has-numbering">%BFTONEMAP High <span class="hljs-keyword">Dynamic</span> Range tonemapping <span class="hljs-keyword">using</span> BF
%
%   The script reduces the <span class="hljs-keyword">dynamic</span> range <span class="hljs-keyword">of</span> an HDR image <span class="hljs-keyword">using</span> the <span class="hljs-function"><span class="hljs-keyword">method</span>
%   <span class="hljs-title">originally</span> <span class="hljs-title">proposed</span> <span class="hljs-title">by</span> <span class="hljs-title">Durand</span> <span class="hljs-title">and</span> <span class="hljs-title">Dorsey</span>, "<span class="hljs-title">Fast</span> <span class="hljs-title">Bilateral</span> <span class="hljs-title">Filtering</span>
%   <span class="hljs-title">for</span> <span class="hljs-title">the</span> <span class="hljs-title">Display</span> <span class="hljs-title">of</span> <span class="hljs-title">High</span>-<span class="hljs-title">Dynamic</span>-<span class="hljs-title">Range</span> <span class="hljs-title">Images</span>",
%   <span class="hljs-title">ACM</span> <span class="hljs-title">Transactions</span> <span class="hljs-title">on</span> <span class="hljs-title">Graphics</span>, 2002.


%% <span class="hljs-title">Load</span> <span class="hljs-title">HDR</span> <span class="hljs-title">image</span> <span class="hljs-title">from</span> <span class="hljs-title">file</span> <span class="hljs-title">and</span> <span class="hljs-title">convert</span> <span class="hljs-title">to</span> <span class="hljs-title">greyscale</span>
<span class="hljs-title">hdr</span> = <span class="hljs-title">double</span><span class="hljs-params">(hdrread(<span class="hljs-string">'smallOffice.hdr'</span>)</span>);</span>
I = <span class="hljs-number">0.2989</span>*hdr(:,:,<span class="hljs-number">1</span>) + <span class="hljs-number">0.587</span>*hdr(:,:,<span class="hljs-number">2</span>) + <span class="hljs-number">0.114</span>*hdr(:,:,<span class="hljs-number">3</span>);
logI = log(I+eps);

%% Perform edge-preserving smoothing <span class="hljs-keyword">using</span> bilateralFilter
base = log(bilateralFilter(I));

%% Compress the base layer <span class="hljs-keyword">and</span> restore detail
compression = <span class="hljs-number">0.25</span>;
detail = logI - base;
<span class="hljs-keyword">OUT</span> = base*compression + detail;
<span class="hljs-keyword">OUT</span> = exp(<span class="hljs-keyword">OUT</span>);

%% Restore color
<span class="hljs-keyword">OUT</span> = <span class="hljs-keyword">OUT</span>./I;
<span class="hljs-keyword">OUT</span> = hdr .* padarray(<span class="hljs-keyword">OUT</span>, [<span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">2</span>], <span class="hljs-string">'circular'</span> , <span class="hljs-string">'post'</span>);


%% <span class="hljs-keyword">Finally</span>, shift, scale, <span class="hljs-keyword">and</span> gamma correct the <span class="hljs-keyword">result</span>
gamma = <span class="hljs-number">1.0</span>/<span class="hljs-number">2.2</span>;
bias = -min(<span class="hljs-keyword">OUT</span>(:));
gain = <span class="hljs-number">0.45</span>;
<span class="hljs-keyword">OUT</span> = (gain*(<span class="hljs-keyword">OUT</span> + bias)).^gamma;

imshow([hdr <span class="hljs-keyword">OUT</span>]);</code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li></ul></pre>



<h1 id="效果"><a name="t4"></a>效果</h1>

<p>bilateralFilter是双边滤波器,若是你找不到合适的,可以到这里<a href="http://people.csail.mit.edu/sparis/bf/%20%E4%B8%80%E4%B8%AA%E5%BF%AB%E9%80%9F%E5%8F%8C%E8%BE%B9%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%9A%84%E5%AE%9E%E7%8E%B0" rel="nofollow" target="_blank">下载</a>。 <br>
</p><center><img src="https://img-blog.csdn.net/20150501165203825" alt="点击看大图" title="效果" height="240"></center><p></p>

<h1 id="参考"><a name="t5"></a>参考</h1>

<blockquote>
  <p>[1]: <a href="http://people.csail.mit.edu/fredo/PUBLI/Siggraph2002/" rel="nofollow" target="_blank">http://people.csail.mit.edu/fredo/PUBLI/Siggraph2002/</a></p>
  
  <p>[2]: <a href="http://www.cnblogs.com/Imageshop/p/3428809.html" rel="nofollow" target="_blank">http://www.cnblogs.com/Imageshop/p/3428809.html</a></p>
  
  <p>[3]: <br>
  <a href="http://baike.baidu.com/link?url=FeAX3SzIdJdyzL4JwHQhB_Nyv4-mDeNF1lUQe7vBBCe5K6RV7y9HGgJDIBmSvdn79OR17vwSWQjARC9U2xi7LJL38X2V27qqkJ6ESSCcAYgPDLZln8oE0JCiHnydMmdG" rel="nofollow" target="_blank">http://baike.baidu.com/link?url=FeAX3SzIdJdyzL4JwHQhB_Nyv4-mDeNF1lUQe7vBBCe5K6RV7y9HGgJDIBmSvdn79OR17vwSWQjARC9U2xi7LJL38X2V27qqkJ6ESSCcAYgPDLZln8oE0JCiHnydMmdG</a> <br>
  [4]: <a href="http://people.csail.mit.edu/sparis/bf/" rel="nofollow" target="_blank">http://people.csail.mit.edu/sparis/bf/</a></p>
</blockquote>



<h1 id="转载请保留以下信息"><a name="t6"></a>转载请保留以下信息</h1>

<table>
<thead>
<tr>
  <th>作者</th>
  <th align="center">日期</th>
  <th align="right">联系方式</th>
</tr>
</thead>
<tbody><tr>
  <td>风吹夏天</td>
  <td align="center">2015年5月1日</td>
  <td align="right">[email protected]</td>
</tr>
</tbody></table>            </div>
            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css">
                </div>

猜你喜欢

转载自blog.csdn.net/xmc_Muncy/article/details/80859837
HDR
今日推荐