高斯拉普拉斯算子:它是如何工作的? (OpenCV)
有谁知道它是如何工作的以及如何使用 OpenCV 来做到这一点? 拉普拉斯算子可以使用 OpenCV 计算, 但结果并不是我所期望的。 我的意思是,我希望图像在背景区域具有大致恒定的对比度,但它是黑色的,边缘是白色的。即使经过高斯滤波器,也存在很多噪声。 我使用高斯滤波器过滤图像,然后应用拉普拉斯。 我认为我想要的是以不同的方式完成的。
Does anybody know how does it work and how to do it using OpenCV?
Laplacian can be calculated using OpenCV,
but the result is not what I expected.
I mean I expect the image to be approximately constant contrast at background regions, but it is black, and edges are white. There are a lot of noise also, even after gauss filter.
I filter image using gaussian filter and then apply laplace.
I think what I want is done by a different way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
高斯拉普拉斯算子是一种边缘检测滤波器;在恒定(“背景”)区域中输出为 0,在有对比度的区域中输出为正或负。您在背景区域看到黑色的原因是 OpenCV 只是为您提供原始输出;您所描述的图像类型(背景为灰色,正/负边缘为黑色或白色)是在将输出缩放到适当的范围后生成的。
输出范围根据实际使用的内核而有所不同,但它始终适合零附近的
(-max, +max)
范围,其中max
是最大输出幅度过滤器内核的;要获得“典型”输出图像,您需要将其缩放到(0, 1)
范围(如果您使用的是 8 位,则为(0, 255)
图像)。您可以使用
cvScale
函数执行必要的缩放,以1/(2*max)
作为缩放因子,并使用0.5
平移。 (或者对于 8 位图像,使用255/(2*max)
缩放和128
移位。)Laplacian of Gaussian is an edge-detection filter; the output is 0 in constant ('background') regions, and positive or negative where there is contrast. The reason why you're seeing black in the background regions is because OpenCV is just giving you the raw output; the kind of image you're describing (gray on background, with positive / negative edges in black or white) is produced after scaling the output into an appropriate range.
The output range varies depending on the actual kernel used, but it's always going to fit in a
(-max, +max)
range around zero wheremax
is the maximum output magnitude of the filter kernel; to get the "typical" output image you need to scale that into a(0, 1)
range (or(0, 255)
if you're using 8-bit images).You can perform the necessary scaling using the
cvScale
function, with1/(2*max)
as the scale factor and0.5
shift. (Or for 8-bit images use255/(2*max)
scale and128
shift.)