C++原型:
void __stdcall BilateralFilter(unsigned char *Src, unsigned char *Joint, unsigned char *Dest, int Width, int Height, int Stride, int DownSampleRate, float SigmaS, float SigmaR, bool UseGaussianBlur)
C#声明:
[DllImport("ImageProcessing.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true)] internal static extern void BilateralFilter(byte* Src, byte* Joint, byte* Dest, int Width, int Height, int Stride, int DownSampleRate, float SigmaS, float SigmaR, bool UseGaussianBlur);
VB.NET声明:
<DllImport("ImageProcessing.dll", CallingConvention := CallingConvention.StdCall, CharSet := CharSet.Unicode, ExactSpelling := True)> _ Friend Shared Sub BilateralFilter(ByVal Src As IntPtr,ByVal Joint As IntPtr,ByVal Dest As IntPtr, ByVal Width As Integer, ByVal Height As Integer, ByVal Stride As Integer, ByVal DownSampleRate As Integer, Byval SigmaS as Single, Byval SigmaR As Single, Byval UseGaussianBlur as boolean) End Sub
VB6.0声明:
Private Declare Sub BilateralFilter Lib "ImageProcessing" (ByVal Src As Long, Byval Joint as Long, ByVal Dest As Long, ByVal Width As Long, ByVal Height As Long, ByVal StrideAs Long, ByVal DownSampleRate As Long, Byval SigmaS as Single, Byval SigmaR as Single, byval UseGaussianBlur as Boolean)
函数说明:
/// <summary> /// 实现快速联合双边滤波,基于<Real-time O(1) Bilateral Filtering, CVPR, 2009>一文,2014.7.20日重新整理, 耗时4个小时,基本没啥改进的了 /// </summary> /// <param name="Src">图像数据部分在内存中的地址。</param> /// <param name="Joint">引导图的数据在内存中的地址,必须和原图具有相同的格式和大小,也可以直接用原图,那么就变成了普通的双边滤波了。</param> /// <param name="Dest">保存处理后的结果的图像数据在内存中的地址,必须和原图具有相同的格式和大小。</param> /// <param name="Width">图像的宽度。</param> /// <param name="Height">图像的高度。</param> /// <param name="Stride">图像的扫描行大小。</param> /// <param name="DownSampleRate">下采样率,取0时不进行下采样,取1时效果和原始的基本没有区别,大于1时如果用于增强则没有问题,用于精细控制时不太行,会有网格出现。</param> /// <param name="SigmaS">控制Spatial Kernel的大小,范围是(0,255],算法速度于这个参数无关。</param> /// <param name="SigmaR">控制Range Kernel的大小,范围是(0,255],算法速度与该参数成反比关系。</param> /// <param name="UseGaussianBlur">Spatical域内的卷积方式,高斯要稍微慢点。</param> /// <remarks>1:Src和Dest可以相同,相同和不同时执行速度无区别。</remarks> /// <remarks>2:InterpolationAmount不能修改,否则在SigmaR较小时,图像会有瑕疵出现。</remarks> /// <remarks>3:函数的主要耗时还是模糊部分,占用约60%的耗时。</remarks>
算法效果:
以上为SigmaS = 10,SigmaR = 25时的处理结果。
原图 联合滤波图 结果图(SigmaS = 100,SigmaR = 15)
处理速度:
I3 M380 2.53GHZ 笔记本上测试:1000 * 1000 彩色像素,用时280ms(SigmaS = 10,SigmaR = 25),该算法的处理和SigmaR成线性关系。
代码情况:
本代码是基于的论文及论文配套代码可从网络上下载到。