# 双边滤波算法的简易实现bilateralFilter

```void bilateralFilter(unsigned char* pSrc, unsigned char* pDest, int width, int height, int radius)
{
float delta = 0.1f;
float eDelta = 1.0f / (2 * delta * delta);

int colorDistTable[256 * 256] = { 0 };
for (int x = 0; x < 256; x++)
{
int  * colorDistTablePtr = colorDistTable + (x * 256);
for (int y = 0; y < 256; y++)
{
int  mod = ((x - y) * (x - y))*(1.0f / 256.0f);
colorDistTablePtr[y] = 256 * exp(-mod * eDelta);
}
}
for (int Y = 0; Y < height; Y++)
{
int Py = Y * width;
unsigned char* LinePD = pDest + Py;
unsigned char* LinePS = pSrc + Py;
for (int X = 0; X < width; X++)
{
int sumPix = 0;
int sum = 0;
int factor = 0;

{
unsigned char* pLine = pSrc + ((Y + i + height) % height)* width;
int cPix = 0;
int  * colorDistPtr = colorDistTable + LinePS[X] * 256;
{
cPix = pLine[ (X + j+width)%width];
factor = colorDistPtr[cPix];
sum += factor;
sumPix += (factor *cPix);
}
}
LinePD[X] = (sumPix / sum);
}
}
}```

抛砖引玉一下，算法思路比较清晰。

58 篇文章51 人订阅

0 条评论

## 相关文章

46790

49970

### SSE图像算法优化系列二：高斯模糊算法的全面优化过程分享（二）。

相关链接： 高斯模糊算法的全面优化过程分享（一）      在高斯模糊算法的全面优化过程分享（一）一文中我们已经给出了一种相当高性能的高斯模糊过程，...

49860

55440

53050

39370

41020

46550

75670

13610