優化的對比度增強算法用於有霧圖像的清晰化處理(算法效果是我目前看到最為穩定的,且對天空具有天然的免疫力,極力推薦有需要的朋友研究)。


    在未談及具體的算法流程前,先貼幾幅用該算法處理的效果。

  不知道各位對這個算法的效果第一印象如何。

      這個算法的原理來自於文章《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.

  結合上述描述以及論文配套的代碼可以很容易的理解這里的道理。論文的配套代碼的實現也很好。

  具體的流程還是請各位仔細的閱讀論文及其代碼,經過我自己的優化和實踐,這個算法確實能得到很不錯的效果,在速度上也能夠達到實時。

      在貼一些效果圖(有的時候只有看到這些圖,才很有成就感)。

 

 

效果測試程序:http://files.cnblogs.com/Imageshop/HazeRemovalBasedonContrastEnhancement.rar

 論文及原作者的代碼下載地址:http://mcl.korea.ac.kr/projects/dehazing/#userconsent# (這個源代碼是OPENCV寫的,估計要配置很久才能順利運行,我反正沒有去弄,只是結合他的論文和代碼在自己實現).

 

 

****************************作者: laviewpbt   時間: 2014.8.20    聯系QQ:  33184777 轉載請保留本行信息**********************

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM