CImg中的blur

I have been assuming for quite some time that "blur" and "get_blur" are Gaussian blurs.

1) I recently noticed that the documentation says it is a Canny-Deriche filter. This confused me because the only Canny-Deriche filter I know is an edge filter.

I did some tests to see if it is in fact a Gaussian blur. Because the Gaussian is the only kernel linear operator, this should hold:

G(s1)*G(s2) = G( sqrt(s1^2 + s2^2) )

I did a test, and it is fairly close, but not equivalent -- the two-pass blurred image was slightly more blurred than the single pass version. This could be due to approximation or round-off errors.

Because a Gaussian is linearly separable, it should also be the case that

G_x(s1)*G_y(s1) = G(s1)

I did a test of this, and they appeared very much equal. So it seems that the blur function is in fact a Gaussian blur. But why is it called Canny-Deriche in the documentation then?

2) Secondly, I am curious how the function is implemented -- does it use 2 passes with recursive filters?


The blur() function in CImg is indeed not a Gaussian one, but it should be close enough for usual applications.

1) The fact is that it is implemented using a recursive Deriche filter which theoretically implements the convolution with the kernel g(x) = exp(-k|x|).
Here, the 'k' parameter is automatically chosen from 'sigma' (the blur amplitude) so that the filter has the same values at 'g(sigma)'.
This is why is is relatively close to a real Gaussian function f(x) = exp(-x*x/2sigma).

2) You are absolutely right, this is implemented as a 2 passes recursive filter.

David.



HoughCircles是OpenCV中的一个函数,可以用于在图像中检测圆形物体。使用HoughCircles函数需要设置一些参数,包括二值化阈值、最小圆半径、最大圆半径、圆心距离等。具体使用方法如下: ```python import cv2 import numpy as np # 读取图片 img = cv2.imread('circle.png', cv2.IMREAD_GRAYSCALE) # 预处理图片 img = cv2.medianBlur(img, 5) cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) # 检测圆形 circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0) # 绘制圆形 circles = np.uint16(np.around(circles)) for i in circles[0, :]: cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2) cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3) # 显示图片 cv2.imshow('detected circles', cimg) cv2.waitKey(0) cv2.destroyAllWindows() ``` 其中,`cv2.HoughCircles`函数的参数含义如下: - `img`:输入图像,必须是单通道(灰度)图像。 - `method`:检测方法,可选参数为`cv2.HOUGH_GRADIENT`和`cv2.HOUGH_STANDARD`。前者是一种基于梯度的方法,后者是一种传统的霍夫变换方法。 - `dp`:累加器分辨率与图像分辨率的比例。dp越小,累加器数组越大。 - `minDist`:检测到的圆心之间的最小距离。 - `param1`:Canny边缘检测的高阈值。 - `param2`:检测阶段圆心累加器阈值,值越小检测到的圆形越多。 - `minRadius`:检测到的圆的最小半径。 - `maxRadius`:检测到的圆的最大半径。 在上面的例子中,我们读取了一张灰度图像,并对其进行了中值滤波和颜色空间转换。然后,使用`cv2.HoughCircles`函数检测圆形,并将检测到的圆形绘制在原图上。最后,显示出图像。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值