matlab如何理解双边滤波实现磨皮

matlab如何理解双边滤波实现磨皮,第1张

1、首先用matlab把周围的像素给加权平均到当前像素。

2、其次权重取决于离当前像素的距离。得到一种带点模糊,又保留边缘的效果。

3、最后就可以很好的理解双边滤波实现磨皮了。

clc

T=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. }

已发至邮箱,查收吧。。。。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8136996.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存