# 用于图像去雾的优化对比度增强算法

## 算法核心1：计算大气光值

I(p)=t(p)J(p)+(1t(p))A

of the pixel values within the region）。记下来，选择具有最高得分的区域，并将其继续划分为更小的四个子矩形。我们重复这个过程直到被选中的区域小于某个提前指定的阈值。例如下图中的红色部分就是最终被选定的区域。在这被选定的区域里，我们选择使得距离 ||(Ir(p),Ig(p),Ib(p))(255,255,255)|| 最小化的颜色（包含 r,g,b 三个分量）来作为大气光的参考值。注意，这样做的意义在于我们希望选择那个离纯白色最近的颜色（也就是最亮的颜色）来作为大气光的参考值。

J(p)=1t(I(p)A)+A

<code class="language-c++ hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;">void dehazing::AirlightEstimation(IplImage* imInput)
{
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nMinDistance = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nDistance;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nX, nY;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nMaxIndex;
double dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>];
double dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>];
double dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>];

float afMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>] = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">{0}</span>;
float afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>] = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">{0}</span>;
float nMaxScore = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nWid = imInput->width;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nHei = imInput->height;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nStep = imInput->widthStep;

<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
IplImage *iplUpperLeft = cvCreateImage(cvSize(nWid/2, nHei/2),IPL_DEPTH_8U, 3);</span>
IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplUpperRight</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>);
IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplLowerLeft</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>);
IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplLowerRight</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>);

IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplR</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplG</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
IplImage <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*iplB</span> = cvCreateImage(cvSize(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),IPL_DEPTH_8U, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);

<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> divide
cvSetImageROI(imInput, cvRect(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
cvCopyImage(imInput, iplUpperLeft);
cvSetImageROI(imInput, cvRect(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>+nWid<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">%2</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, nWid, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
cvCopyImage(imInput, iplUpperRight);
cvSetImageROI(imInput, cvRect(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>+nHei<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">%2</span>, nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, nHei));
cvCopyImage(imInput, iplLowerLeft);
cvSetImageROI(imInput, cvRect(nWid/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>+nWid<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">%2</span>, nHei/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>+nHei<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">%2</span>, nWid, nHei));
cvCopyImage(imInput, iplLowerRight);

<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> compare to threshold(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">200</span>) --> bigger than threshold, divide the block
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nHei<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nWid</span> > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">200</span>)
{
<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> compute the mean <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> std-dev in the <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
// upper left <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
cvCvtPixToPlane(iplUpperLeft, iplR, iplG, iplB, 0);</span>

cvMean_StdDev(iplR, dpMean, dpStds);
cvMean_StdDev(iplG, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
cvMean_StdDev(iplB, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>);
<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> dpScore: mean - std-dev
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];

afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = (float)(dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]);

nMaxScore = afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
nMaxIndex = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;

<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> upper right <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
cvCvtPixToPlane(iplUpperRight, iplR, iplG, iplB, 0);</span>

cvMean_StdDev(iplR, dpMean, dpStds);
cvMean_StdDev(iplG, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
cvMean_StdDev(iplB, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>);

dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];

afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = (float)(dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]);

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] > nMaxScore)
{
nMaxScore = afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
nMaxIndex = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
}

// lower left <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
cvCvtPixToPlane(iplLowerLeft, iplR, iplG, iplB, 0);</span>

cvMean_StdDev(iplR, dpMean, dpStds);
cvMean_StdDev(iplG, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
cvMean_StdDev(iplB, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>);

dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];

afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = (float)(dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]);

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] > nMaxScore)
{
nMaxScore = afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];
nMaxIndex = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;
}

// lower right <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
cvCvtPixToPlane(iplLowerRight, iplR, iplG, iplB, 0);</span>

cvMean_StdDev(iplR, dpMean, dpStds);
cvMean_StdDev(iplG, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
cvMean_StdDev(iplB, dpMean+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, dpStds+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>);

dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = dpMean[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]-dpStds[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];

afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>] = (float)(dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+dpScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]);

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>] > nMaxScore)
{
nMaxScore = afScore[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>];
nMaxIndex = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>;
}

// <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">select</span> the <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block, which has maximum score
switch (nMaxIndex)
{</span>
case <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:
AirlightEstimation(iplUpperLeft); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
case <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:
AirlightEstimation(iplUpperRight); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
case <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>:
AirlightEstimation(iplLowerLeft); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
case <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>:
AirlightEstimation(iplLowerRight); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
}
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>
{
<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">select</span> the atmospheric light value in the <span class="hljs-sub" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sub</span>-block
for(nY=0;</span> nY<nHei; nY++)
{
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(nX=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; nX<nWid; nX++)
{
<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-r, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-g, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-b
nDistance = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sqrt</span>(float(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*float</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>])
+float(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*float</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>])
+float(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*float</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>-(uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>])));
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nMinDistance > nDistance)
{
nMinDistance = nDistance;
m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] = (uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>];
m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] = (uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];
m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>] = (uchar)imInput->imageData[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nStep</span>+nX<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*3</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];
}
}
}
}
cvReleaseImage(&iplUpperLeft);
cvReleaseImage(&iplUpperRight);
cvReleaseImage(&iplLowerLeft);
cvReleaseImage(&iplLowerRight);

cvReleaseImage(&iplR);
cvReleaseImage(&iplG);
cvReleaseImage(&iplB);
}

</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li><li style="box-sizing: border-box; padding: 0px 5px;">106</li><li style="box-sizing: border-box; padding: 0px 5px;">107</li><li style="box-sizing: border-box; padding: 0px 5px;">108</li><li style="box-sizing: border-box; padding: 0px 5px;">109</li><li style="box-sizing: border-box; padding: 0px 5px;">110</li><li style="box-sizing: border-box; padding: 0px 5px;">111</li><li style="box-sizing: border-box; padding: 0px 5px;">112</li><li style="box-sizing: border-box; padding: 0px 5px;">113</li><li style="box-sizing: border-box; padding: 0px 5px;">114</li><li style="box-sizing: border-box; padding: 0px 5px;">115</li><li style="box-sizing: border-box; padding: 0px 5px;">116</li><li style="box-sizing: border-box; padding: 0px 5px;">117</li><li style="box-sizing: border-box; padding: 0px 5px;">118</li><li style="box-sizing: border-box; padding: 0px 5px;">119</li><li style="box-sizing: border-box; padding: 0px 5px;">120</li><li style="box-sizing: border-box; padding: 0px 5px;">121</li><li style="box-sizing: border-box; padding: 0px 5px;">122</li><li style="box-sizing: border-box; padding: 0px 5px;">123</li><li style="box-sizing: border-box; padding: 0px 5px;">124</li><li style="box-sizing: border-box; padding: 0px 5px;">125</li><li style="box-sizing: border-box; padding: 0px 5px;">126</li><li style="box-sizing: border-box; padding: 0px 5px;">127</li><li style="box-sizing: border-box; padding: 0px 5px;">128</li><li style="box-sizing: border-box; padding: 0px 5px;">129</li><li style="box-sizing: border-box; padding: 0px 5px;">130</li><li style="box-sizing: border-box; padding: 0px 5px;">131</li><li style="box-sizing: border-box; padding: 0px 5px;">132</li><li style="box-sizing: border-box; padding: 0px 5px;">133</li><li style="box-sizing: border-box; padding: 0px 5px;">134</li><li style="box-sizing: border-box; padding: 0px 5px;">135</li><li style="box-sizing: border-box; padding: 0px 5px;">136</li><li style="box-sizing: border-box; padding: 0px 5px;">137</li><li style="box-sizing: border-box; padding: 0px 5px;">138</li><li style="box-sizing: border-box; padding: 0px 5px;">139</li><li style="box-sizing: border-box; padding: 0px 5px;">140</li><li style="box-sizing: border-box; padding: 0px 5px;">141</li><li style="box-sizing: border-box; padding: 0px 5px;">142</li><li style="box-sizing: border-box; padding: 0px 5px;">143</li><li style="box-sizing: border-box; padding: 0px 5px;">144</li><li style="box-sizing: border-box; padding: 0px 5px;">145</li><li style="box-sizing: border-box; padding: 0px 5px;">146</li><li style="box-sizing: border-box; padding: 0px 5px;">147</li><li style="box-sizing: border-box; padding: 0px 5px;">148</li><li style="box-sizing: border-box; padding: 0px 5px;">149</li><li style="box-sizing: border-box; padding: 0px 5px;">150</li><li style="box-sizing: border-box; padding: 0px 5px;">151</li><li style="box-sizing: border-box; padding: 0px 5px;">152</li><li style="box-sizing: border-box; padding: 0px 5px;">153</li><li style="box-sizing: border-box; padding: 0px 5px;">154</li><li style="box-sizing: border-box; padding: 0px 5px;">155</li><li style="box-sizing: border-box; padding: 0px 5px;">156</li><li style="box-sizing: border-box; padding: 0px 5px;">157</li><li style="box-sizing: border-box; padding: 0px 5px;">158</li><li style="box-sizing: border-box; padding: 0px 5px;">159</li><li style="box-sizing: border-box; padding: 0px 5px;">160</li><li style="box-sizing: border-box; padding: 0px 5px;">161</li><li style="box-sizing: border-box; padding: 0px 5px;">162</li><li style="box-sizing: border-box; padding: 0px 5px;">163</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li><li style="box-sizing: border-box; padding: 0px 5px;">106</li><li style="box-sizing: border-box; padding: 0px 5px;">107</li><li style="box-sizing: border-box; padding: 0px 5px;">108</li><li style="box-sizing: border-box; padding: 0px 5px;">109</li><li style="box-sizing: border-box; padding: 0px 5px;">110</li><li style="box-sizing: border-box; padding: 0px 5px;">111</li><li style="box-sizing: border-box; padding: 0px 5px;">112</li><li style="box-sizing: border-box; padding: 0px 5px;">113</li><li style="box-sizing: border-box; padding: 0px 5px;">114</li><li style="box-sizing: border-box; padding: 0px 5px;">115</li><li style="box-sizing: border-box; padding: 0px 5px;">116</li><li style="box-sizing: border-box; padding: 0px 5px;">117</li><li style="box-sizing: border-box; padding: 0px 5px;">118</li><li style="box-sizing: border-box; padding: 0px 5px;">119</li><li style="box-sizing: border-box; padding: 0px 5px;">120</li><li style="box-sizing: border-box; padding: 0px 5px;">121</li><li style="box-sizing: border-box; padding: 0px 5px;">122</li><li style="box-sizing: border-box; padding: 0px 5px;">123</li><li style="box-sizing: border-box; padding: 0px 5px;">124</li><li style="box-sizing: border-box; padding: 0px 5px;">125</li><li style="box-sizing: border-box; padding: 0px 5px;">126</li><li style="box-sizing: border-box; padding: 0px 5px;">127</li><li style="box-sizing: border-box; padding: 0px 5px;">128</li><li style="box-sizing: border-box; padding: 0px 5px;">129</li><li style="box-sizing: border-box; padding: 0px 5px;">130</li><li style="box-sizing: border-box; padding: 0px 5px;">131</li><li style="box-sizing: border-box; padding: 0px 5px;">132</li><li style="box-sizing: border-box; padding: 0px 5px;">133</li><li style="box-sizing: border-box; padding: 0px 5px;">134</li><li style="box-sizing: border-box; padding: 0px 5px;">135</li><li style="box-sizing: border-box; padding: 0px 5px;">136</li><li style="box-sizing: border-box; padding: 0px 5px;">137</li><li style="box-sizing: border-box; padding: 0px 5px;">138</li><li style="box-sizing: border-box; padding: 0px 5px;">139</li><li style="box-sizing: border-box; padding: 0px 5px;">140</li><li style="box-sizing: border-box; padding: 0px 5px;">141</li><li style="box-sizing: border-box; padding: 0px 5px;">142</li><li style="box-sizing: border-box; padding: 0px 5px;">143</li><li style="box-sizing: border-box; padding: 0px 5px;">144</li><li style="box-sizing: border-box; padding: 0px 5px;">145</li><li style="box-sizing: border-box; padding: 0px 5px;">146</li><li style="box-sizing: border-box; padding: 0px 5px;">147</li><li style="box-sizing: border-box; padding: 0px 5px;">148</li><li style="box-sizing: border-box; padding: 0px 5px;">149</li><li style="box-sizing: border-box; padding: 0px 5px;">150</li><li style="box-sizing: border-box; padding: 0px 5px;">151</li><li style="box-sizing: border-box; padding: 0px 5px;">152</li><li style="box-sizing: border-box; padding: 0px 5px;">153</li><li style="box-sizing: border-box; padding: 0px 5px;">154</li><li style="box-sizing: border-box; padding: 0px 5px;">155</li><li style="box-sizing: border-box; padding: 0px 5px;">156</li><li style="box-sizing: border-box; padding: 0px 5px;">157</li><li style="box-sizing: border-box; padding: 0px 5px;">158</li><li style="box-sizing: border-box; padding: 0px 5px;">159</li><li style="box-sizing: border-box; padding: 0px 5px;">160</li><li style="box-sizing: border-box; padding: 0px 5px;">161</li><li style="box-sizing: border-box; padding: 0px 5px;">162</li><li style="box-sizing: border-box; padding: 0px 5px;">163</li></ul>

<code class="language-matlab hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;">
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">function</span> <span class="hljs-title" style="box-sizing: border-box;">airlight</span> = <span class="hljs-title" style="box-sizing: border-box;">est_airlight</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(img)</span></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%compute atmospheric light A through hierarchical</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%searching method based on the quad-tree subdivision</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">global</span> best;
<span class="hljs-matrix" style="box-sizing: border-box;">[w,h,z]</span> = <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">size</span>(img);
img = double(img);

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> w*h > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">200</span>
lu = img(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(w/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(h/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),:);
ru = img(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(w/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(h/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>):h,:);
lb = img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(w/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>):w,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(h/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>),:);
rb = img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(w/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>):w,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">floor</span>(h/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>):h,:);

lu_m_r = mean(mean(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)));
lu_m_g = mean(mean(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)));
lu_m_b = mean(mean(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>)));

ru_m_r = mean(mean(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)));
ru_m_g = mean(mean(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)));
ru_m_b = mean(mean(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>)));

lb_m_r = mean(mean(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)));
lb_m_g = mean(mean(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)));
lb_m_b = mean(mean(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>)));

rb_m_r = mean(mean(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)));
rb_m_g = mean(mean(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)));
rb_m_b = mean(mean(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>)));

lu_s_r = std2(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>));
lu_s_g = std2(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
lu_s_b = std2(lu(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>));

ru_s_r = std2(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>));
ru_s_g = std2(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
ru_s_b = std2(ru(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>));

lb_s_r = std2(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>));
lb_s_g = std2(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
lb_s_b = std2(lb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>));

rb_s_r = std2(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>));
rb_s_g = std2(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>));
rb_s_b = std2(rb(:,:,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>));

score0 = lu_m_r + lu_m_g + lu_m_b - lu_s_r - lu_s_g - lu_s_b;
score1 = ru_m_r + ru_m_g + ru_m_b - ru_s_r - ru_s_g - ru_s_b;
score2 = lb_m_r + lb_m_g + lb_m_b - lb_s_r - lb_s_g - lb_s_b;
score3 = rb_m_r + rb_m_g + rb_m_b - rb_s_r - rb_s_g - rb_s_b;
x = <span class="hljs-matrix" style="box-sizing: border-box;">[score0,score1,score2,score3]</span>;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> max(x) == score0
est_airlight(lu);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">elseif</span> max(x) == score1
est_airlight(ru);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">elseif</span> max(x) == score2
est_airlight(lb);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">elseif</span> max(x) == score3
est_airlight(rb);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:w
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:h
nMinDistance = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>;
distance = <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sqrt</span>((<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span> - img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)).^<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> +  (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span> - img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)).^<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> + (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span> - img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>)).^<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> nMinDistance > distance
nMinDistance = distance;
best = img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>,:);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
airlight =best;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li></ul>

## 算法核心2：透射率的计算

CMSE=p=1N=(Jc(p)J¯c)2N

J(p)=1t(I(p)A)+A

CMSE=p=1N=(Ic(p)I¯c)2t2N

Econtrast=c{r,g,b}pB(Jc(p)J¯c)2NB=c{r,g,b}pB(Ic(p)I¯c)2t2NB

E=Econtrast+λLEloss

<code class="language-c++ hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;">float dehazing::NFTrsEstimationColor(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*pnImageR</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*pnImageG</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*pnImageB</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nStartX, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nStartY, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nWid, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nHei)
{
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nCounter;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nX, nY;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nEndX;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nEndY;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nOutR, nOutG, nOutB;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nSquaredOut;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nSumofOuts;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nSumofSquaredOuts;
float fTrans, fOptTrs;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nTrans;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nSumofSLoss;
float fCost, fMinCost, fMean;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> nNumberofPixels, nLossCount;

nEndX = __min(nStartX+m_nTBlockSize, nWid);
nEndY = __min(nStartY+m_nTBlockSize, nHei);

nNumberofPixels = (nEndY-nStartY)<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*(</span>nEndX-nStartX) * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>;

fTrans = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>f;
nTrans = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">427</span>;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(nCounter=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; nCounter<<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>; nCounter++)
{
nSumofSLoss = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
nLossCount = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
nSumofSquaredOuts = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
nSumofOuts = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(nY=nStartY; nY<nEndY; nY++)
{
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(nX=nStartX; nX<nEndX; nX++)
{

nOutB = ((pnImageB[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nWid</span>+nX] - m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nTrans</span> + <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*m_anAirlight</span>[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>])>><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>; <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span> (I-A)/t + A --> ((I-A)<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*k</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*128</span> + A<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*128</span>)/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span>
nOutG = ((pnImageG[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nWid</span>+nX] - m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nTrans</span> + <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*m_anAirlight</span>[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>])>><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>;
nOutR = ((pnImageR[nY<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nWid</span>+nX] - m_anAirlight[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>])<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*nTrans</span> + <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*m_anAirlight</span>[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>])>><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>;

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutR><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)
{
nSumofSLoss += (nOutR - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*(</span>nOutR - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>);
nLossCount++;
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutR < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>)
{
nSumofSLoss += nOutR * nOutR;
nLossCount++;
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutG><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)
{
nSumofSLoss += (nOutG - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*(</span>nOutG - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>);
nLossCount++;
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutG < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>)
{
nSumofSLoss += nOutG * nOutG;
nLossCount++;
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutB><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)
{
nSumofSLoss += (nOutB - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>)<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*(</span>nOutB - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255</span>);
nLossCount++;
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nOutB < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>)
{
nSumofSLoss += nOutB * nOutB;
nLossCount++;
}
nSumofSquaredOuts += nOutB * nOutB + nOutR * nOutR + nOutG * nOutG;;
nSumofOuts += nOutR + nOutG + nOutB;
}
}
fMean = (float)(nSumofOuts)/(float)(nNumberofPixels);
fCost = m_fLambda1 * (float)nSumofSLoss/(float)(nNumberofPixels)
- ((float)nSumofSquaredOuts/(float)nNumberofPixels - fMean<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*fMean</span>);

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(nCounter==<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> || fMinCost > fCost)
{
fMinCost = fCost;
fOptTrs = fTrans;
}

fTrans += <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>f;
nTrans = (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span>)(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.0</span>f/fTrans<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*128</span>.0f);
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> fOptTrs;
}
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li></ul>

## 实验效果

• 算法对于天空部分的处理相当到位，更优于Kaiming He的暗通道先验算法；
• 对比度过大时，图像很容易发暗，可以后期将图片稍微调亮一些。
• 算法本身是从对比增强的角度来进行去雾操作的，所以你可以看出结果自动带对比度增强加成，所以这个算法所取得的结果通常更加鲜亮。

===========

===========

## 参考文献与推荐阅读材料

[1] Kim, J.H., Jang, W.D., Sim, J.Y. and Kim, C.S., 2013. Optimized contrast enhancement for real-time image and video dehazing. Journal of Visual Communication and Image Representation, 24(3), pp.410-425. （百度云下载链接）
[2] 原作者的项目主页——可以下载到基于OpenCV实现的程序源代码
[3] laviewpbt更早之前发布的一篇研究该算法的文章——该博客上同时包含有很多其他图像去雾方面的文章，推荐有兴趣的读者参考