2、其次权重取决于离当前像素的距离。得到一种带点模糊,又保留边缘的效果。
3、最后就可以很好的理解双边滤波实现磨皮了。
clcT=255
Delta =80
Gamma = pi/(2*T)
Rho= Gamma * Delta
Color = ['b','g','r','c','m','y','k']
x=-T:T
y1=exp(-x.^2/(2*Delta*Delta))
plot(x,y1,'--b','LineWidth',2)
hold on
for k=2:7
y2= cos(Gamma .* x/ (Rho * sqrt(k))).^(k)
plot(x,y2,Color(k))
end
[cpp] view plaincopyprint?1. UCHAR3 BBColor(int posX , int posY)
2. {
3. int centerItemIndex = posY * picWidth4 + posX * 3 , neighbourItemIndex
4. int weightIndex
5. double gsAccumWeight = 0
6. double accumColor = 0
7.
8. // 计算各个采样点处的Gaussian权重,包括closeness,similarity
9. for(int i = -number i <= number ++i)
10. {
11. for(int j = -number j <= number ++j)
12. {
13. weightIndex = (i + number) * (number * 2 + 1) + (j + number)
14. neighbourItemIndex = min(noiseImageHeight - 1 , max(0 , posY + j * radius)) * picWidth4 +
15. min(noiseImageWidth - 1 , max(0 , posX + i * radius)) * 3
16.
17. pCSWeight[weightIndex] = LookupGSWeightTable(pSrcDataBuffer[neighbourItemIndex] , pSrcDataBuffer[centerItemIndex])
18. pCSWeight[weightIndex] = pGSWeight[weightIndex] * pGCWeight[weightIndex]
19. gsAccumWeight += pCSWeight[weightIndex]
20. }
21. }
22.
23. // 单位化权重因子
24. gsAccumWeight = 1 / gsAccumWeight
25. for(int i = -number i <= number ++i)
26. {
27. for(int j = -number j <= number ++j)
28. {
29. weightIndex = (i + number) * (number * 2 + 1) + (j + number)
30. pCSWeight[weightIndex] *= gsAccumWeight
31. }
32. }
33.
34. // 计算最终的颜色并返回
35. for(int i = -number i <= number ++i)
36. {
37. for(int j = -number j <= number ++j)
38. {
39. weightIndex = (i + number) * (number * 2 + 1) + (j + number)
40. neighbourItemIndex = min(noiseImageHeight - 1 , max(0 , posY + j * radius)) * picWidth4 +
41. min(noiseImageWidth - 1 , max(0 , posX + i * radius)) * 3
42. accumColor += pSrcDataBuffer[neighbourItemIndex + 0] * pCSWeight[weightIndex]
43. }
44. }
45.
46. return UCHAR3(accumColor , accumColor , accumColor)
47. }
已发至邮箱,查收吧。。。。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)