HazeRemovalBasedOnDarkChannelPrior(基于暗通道的去雾)

C++原型:

void __stdcall HazeRemovalBasedOnDarkChannelPrior(unsigned char *Src, unsigned char * Dest, int Width, int Height, int Stride, float SubSample)

C#声明:

[DllImport("ImageProcessing.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static extern void HazeRemovalBasedOnDarkChannelPrior(byte* Src, byte* Dest, int Width, int Height, int Stride, float SubSample);

VB.NET声明:

<DllImport("ImageProcessing.dll", CallingConvention := CallingConvention.StdCall, CharSet := CharSet.Unicode, ExactSpelling := True)> _
Friend Shared Sub HazeRemovalBasedOnDarkChannelPrior(ByVal Src As IntPtr, ByVal Dest As IntPtr, ByVal Width As Integer, ByVal Height As Integer, ByVal Stride As Integer, ByVal SubSample As Single) 
End Sub

VB6.0声明:

Private Declare Sub HazeRemovalBasedOnDarkChannelPrior Lib "ImageProcessing" (ByVal Src As Long, ByVal Dest As Long, ByVal Width As Long, ByVal Height As Long, ByVal Stride As Long, ByVal SubSample As Single)

函数说明:

/// <summary>
///    实现功能:实现基于暗通道的去雾算法。
///    参考论文:Single Image Haze RemovalUsing Dark Channel Prior  Kaiming He, Jian Sun, and Xiaoou Tang, Fellow, IEEE
///         Single image dehazing Algorithms based on sky region segmentation
/// </summary>
/// <param name="Src">待去雾图像数据在内存的起始地址。</param>
/// <param name="Dest">去雾后的图像数据在内存的起始地址。</param>
/// <param name="Width">图像的宽度。</param>
/// <param name="Height">图像的高度。</param>
/// <param name="Stride">图像的扫描行大小。</param>
/// <param name="SubSample">用于下取样的参数,建议取值范围[0.25,1]。</param>
/// <remarks> 1: 只处理24位图像。</remarks>
/// <remarks> 2: Src和Dest可以相同,相同和不同时速度无差异。</remarks>
/// <remarks> 3: 采用了下采样优化算法,在保留去雾效果的同时,提高了算法的实时性。</remarks>
/// <remarks> 4: 下采样参数不易小于0.5,否则用于缩放所占用的时间可能会比小图计算透射率带来的时间收益还大,建议取值0.25。 </remarks>

开发历程:

  原始的暗通道去雾算法有诸多的缺点,本函数历经多次改版,目前已经做到了速度和效果都比较理想的程度。考虑很多使用者对函数的内在本质不了解,本函数仅仅保留了一个下取样的可调节参数,用于使用者决定效果和速度的平衡,其他参数则根据作者的经验取了相对效果好的值。

算法原理:

  主要是基于何凯明的暗通道方式进行去雾,但是针对何的方式对天空处理不好,采用了简单的天空识别方案,能有效地避免天空部位不被过渡增强,同时保证其他部分能有效去雾。

算法效果:

      

      

      

      

      

      

      

      

    

      

      

      

      

      

      

处理速度:

  I3  M380 2.53GHZ 笔记本上测试:1000 * 1000 彩色像素、SubSample = 0.25,用时28ms。

内部使用到的相关函数:

extern void MinValue(unsigned char *Src, unsigned char *Dest, int Width, int Height, int Stride, int Radius);
extern void GuidedFilterF(float *Src, float *Guide, float *Dest, int Width, int Height, int Radius, float eps);
extern void Resample(unsigned char *Src, int SrcWidth, int SrcHeight, int SrcStride, unsigned char *Dest, int DestWidth, int DestHeight, int DestStride, int InterpolationMode);
extern void GammaCorrection(unsigned char *Src, unsigned char *Dest, int Width, int Height, int Stride, float Gamma);
extern void FindEdges(unsigned char *Src, unsigned char *Dest, int Width, int Height, int Stride);
extern void DecolorizationWithContrastPreserved(unsigned char *Src, unsigned char *Dest, int Width, int Height, int StrideS, int StrideD, bool FastMode = true, int Level = 64, float Sigma = 0.05);
extern void GetEveryChannelHistgram(unsigned char *Src, int Width, int Height, int Stride, int *HistgramB, int *HistgramG, int *HistgramR);
extern void Invert(unsigned char *Src, unsigned char *Dest, int Width, int Height, int Stride);

代码情况:

      代码本身不好并行了,但内部的GuideFilter中使用的BoxBlur可并行。

 

posted @ 2014-10-01 23:25  Imageshop  阅读(1370)  评论(0编辑  收藏  举报