优化的对比度增强算法用于有雾图像的清晰化处理(算法效果是我目前看到最为稳定的,且对天空具有天然的免疫力,极力推荐有需要的朋友研究)。

    在未谈及具体的算法流程前,先贴几幅用该算法处理的效果。

  不知道各位对这个算法的效果第一印象如何。

      这个算法的原理来自于文章《Optimized contrast enhancement for real-time image and video dehazing》,作者是韩国人。

      这个算法也是基于大气散射模型:

          

   和现在一些常见的去雾文章有明显的不同的是,这篇文章的并不是基于暗通道原理的,也不是把重点强调在透射率图的细化上,而是提出了一种新的得到粗透射率图的方法。并且文章分别讲到了静态图像和视频图像的去雾,这里我只研究了静态图的去雾。

      对于透射率图,文章提出了一个cost function,这个cost function是基于以下两点考虑的:

      1、对于有雾图像,其整体的对比比较低,因此去雾后的对比度要尽量的高,文中给出了三种测评一幅图像对比度的方式,这里选用的是第一种:

                    

    公式具体的意义可见论文。注意上面的公式都是对去雾图进行的处理。

  2、 由于对比度得到增强,可能会导致部分像素的调整值超出了0和255的范围,这样就会造成信息的损失以及视觉上的瑕疵。因此提出了一个信息量损失的计算公式:

                                                

     一个好的透射率图应该使得总的损失最小:

                                      

       其中Lamda值用于控制对比度和信息损失之间的重要性。

            进行上述过程还有一个重要的前提就是:对于一小块图像,我们认为他的透射率是一样的,以下作者提供的代码表面了这一点:

for(nY=0; nY<nHei; nY+=m_nTBlockSize)
{
    for(nX=0; nX<nWid; nX+=m_nTBlockSize)
    {
        fTrans = NFTrsEstimationPColor(pnImageR, pnImageG, pnImageB, pnImageRP, pnImageGP, pnImageBP, pfTransmissionP, __max(nX, 0), __max(nY, 0), nWid, nHei);
        for(nYstep=nY; nYstep<nY+m_nTBlockSize; nYstep++)
        {
            for(nXstep=nX; nXstep<nX+m_nTBlockSize; nXstep++)
            {
                pfTransmission[nYstep*nWid+nXstep] = fTrans;
            }
        }
    }
}

  其中的NFTrsEstimationPColor是用来估计一个块的最佳透射率值,作者在编程时,是将透射率按照0.1的间距进行取样,然后找到使得上式最小值得那个透射率作为这个块的透射率。

nEndX = __min(nStartX+m_nTBlockSize, nWid); // End point of the block
nEndY = __min(nStartY+m_nTBlockSize, nHei); // End point of the block

nNumberofPixels = (nEndY-nStartY)*(nEndX-nStartX);    

fTrans = 0.3f;    // Init trans is started from 0.3
nTrans = 427;    // Convert transmission to integer 

for(nCounter=0; nCounter<7; nCounter++)
{
    nSumofSLoss = 0;
    nLossCount = 0;
    nSumofSquaredOuts = 0;
    nSumofOuts = 0;
    for(nY=nStartY; nY<nEndY; nY++)
    {
        for(nX=nStartX; nX<nEndX; nX++)
        {
            nOut = ((pnImageY[nY*nWid+nX] - m_nAirlight)*nTrans + 128*m_nAirlight)>>7; // (I-A)/t + A --> ((I-A)*k*128 + A*128)/128
            nSquaredOut = nOut * nOut;

            if(nOut>255)
            {
                nSumofSLoss += (nOut - 255)*(nOut - 255);
                nLossCount++;
            }
            else if(nOut < 0)
            {
                nSumofSLoss += nSquaredOut;
                nLossCount++;
            }
            nSumofSquaredOuts += nSquaredOut;
            nSumofOuts += nOut;
        }
    }
    fMean = (float)(nSumofOuts)/(float)(nNumberofPixels);  
    fCost = m_fLambda1 * (float)nSumofSLoss/(float)(nNumberofPixels) 
        - ((float)nSumofSquaredOuts/(float)nNumberofPixels - fMean*fMean); 
        
    if(nCounter==0 || fMinCost > fCost)
    {
        fMinCost = fCost;
        fOptTrs = fTrans;
    }

    fTrans += 0.1f;
    nTrans = (int)(1.0f/fTrans*128.0f);
}

  朋友们有没有看到上面的代码中的最小透射率是0.3,我个人认为这个只能够有效的避免天空部位被过增强。

      文中提到了这个方法也可以看成是何凯明的暗通道去雾算法的一个更广义的定义。

     在这个文章,还提出了另外一个和其他算法不同的东西,就是全局大气光A的获取,其主要原理是: the variance of pixel values is generally low in hazy regions, e.g. sky. 具体的操作流程是:

       we first divide an input image into four rectangular regions. We then define the score of each region as the average pixel value subtracted by the standard deviation of the pixel values within the region. Then, we select the region with the highest score and divide it further into four smaller regions.We repeat this process until the size of the selected region is smaller than a pre-specified threshold. Within the selected region, we choose the color vector, which minimizes the distance ||(R,G,B) -(255,255,255)||as the atmospheric light. By minimizing the distance from the pure white vector(255,255,255), we attempt to choose the atmospheric light that is as bright as possible.

  结合上述描述以及论文配套的代码可以很容易的理解这里的道理。论文的配套代码的实现也很好。

  具体的流程还是请各位仔细的阅读论文及其代码,经过我自己的优化和实践,这个算法确实能得到很不错的效果,在速度上也能够达到实时。

      在贴一些效果图(有的时候只有看到这些图,才很有成就感)。

 

 

效果测试程序:https://files.cnblogs.com/Imageshop/HazeRemovalBasedonContrastEnhancement.rar

 论文及原作者的代码下载地址:http://mcl.korea.ac.kr/projects/dehazing/#userconsent# (这个源代码是OPENCV写的,估计要配置很久才能顺利运行,我反正没有去弄,只是结合他的论文和代码在自己实现).

 

 

****************************作者: laviewpbt   时间: 2014.8.20    联系QQ:  33184777 转载请保留本行信息**********************

 

posted @ 2014-08-20 20:39  Imageshop  阅读(32108)  评论(45编辑  收藏  举报