HazeRemovalBasedonContrastEnhancement(对比度增强去雾)
C#原型:
void __stdcall HazeRemovalBasedonContrastEnhancement(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 HazeRemovalBasedonContrastEnhancement(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 HazeRemovalBasedonContrastEnhancement(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声明:
Private Declare Sub HazeRemovalBasedonContrastEnhancement 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> /// 实现功能:实现基于对比度增强的图像去雾算法。 /// 参考论文:Optimized contrast enhancement for real-time image and video dehazing /// 整理时间:2014.8.19 /// </summary> /// <param name="Src">需要处理的图像数据部分在内存中的地址,只能处理24位真彩色。</param> /// <param name="Dest">保存处理结果的图像数据地址,必须和Src具有相同的大小和格式。</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,用时50ms。
内部使用到的相关函数:
extern void GuidedFilter(unsigned char *Src, unsigned char *Guide, unsigned char *Dest, int Width, int Height, int Stride, int Radius, float eps); extern void Resample(unsigned char * Src, int Width, int Height, int Stride, unsigned char * Dest, int NewWidth, int NewHeight, int NewStride, int InterpolationMode); extern void GetEveryChannelMeanAndStdDev(unsigned char *Src, int Width, int Height, int Stride, float &MeanB, float &MeanG, float &MeanR, float &StdDevB, float &StdDevG, float &StdDevR); 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 GammaCorrection(unsigned char *Src, unsigned char *Dest, int Width, int Height, int Stride, float Gamma);
代码情况:
此代码可出售。