小言_互联网的博客

在OpenCV里实现导向滤波

676人阅读  评论(0)

前面学习了双边滤波和联合滤波,都可以保边滤波,计算方式比较类似,都是使用相似性权重模板,下面来介绍一种不依赖于权重模板的保边滤波的另外一种方法—导向滤波。导向滤波比前面两种滤波优点有计算速度快,并且细节增强,平滑效果更好。导向图滤波是一种图像滤波技术 ,通过一张引导图G(导向图),对目标图像P(输入图像)进行滤波处理,使得最后的输出图像大体上与目标图像P相似,但是纹理部分与引导图G相似。其典型应用有两个:保边图像平滑,抠图。

它的原理如下:

 

在opencv已经实现相应的算法,可以采用下面例子来使用:

#python 3.7.4,opencv4.1
#蔡军生 https://blog.csdn.net/caimouse/article/details/51749579
#
import cv2
import numpy as np

#图片的路径
imgname = "imgjbf.png"

#读取图片
image = cv2.imread(imgname, cv2.IMREAD_COLOR)

#图片的高度和宽度
h,w = image.shape[:2]
print('imagesize={}-{}'.format(w,h))

#显示原图
cv2.imshow("Image",image)

#平滑
out = cv2.ximgproc.guidedFilter(image,image,10,800)

cv2.imshow("out",out)


cv2.waitKey(0)
cv2.destroyAllWindows()

结果输出如下:

输入图片

输出图片

调用函数定义如下:

 

dst

=

cv.ximgproc.guidedFilter(

guide, src, radius, eps[, dst[, dDepth]]

)

guide

guided image (or array of images) with up to 3 channels, if it have more then 3 channels then only first 3 channels will be used.

src

filtering image with any numbers of channels.

dst

output image.

radius

radius of Guided Filter.

eps

regularization term of Guided Filter. eps2 is similar to the sigma in the color space into bilateralFilter.

dDepth

optional depth of the output image.

               

https://blog.csdn.net/caimouse/article/details/51749579


转载:https://blog.csdn.net/caimouse/article/details/101216726
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场