使用处理进行 Canny 边缘检测
我正在寻找处理语言中 Canny 边缘检测的复制粘贴实现。尽管我对java非常了解,但我对图像处理的了解为零,对处理的了解也很少。
一些处理专家可以告诉我是否有办法实现这个 http://www.tomgibara .com/computer-vision/CannyEdgeDetector.java 正在处理中?
I am looking for a copy paste implementation of Canny Edge Detection in the processing language. I have zero idea about Image processing and very little clue about Processing, though I understand java pretty well.
Can some processing expert tell me if there is a way of implementing this http://www.tomgibara.com/computer-vision/CannyEdgeDetector.java in processing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为如果你从 Java 的角度来对待处理,那么一些问题就可以很容易地解决。这意味着您可以像这样使用 Java 类。
对于演示,我使用您共享的实现。
>>原始图像
>>更改的图像
>>代码
I think if you treat
processing
in lights ofJava
then some of the problems could be solved very easily. What it means is that you can use Java classes as such.For the demo I am using the implementation which you have shared.
>>Original Image
>>Changed Image
>>Code
我花了一些时间研究 Gibara Canny 的实现,并且我倾向于同意 Settembrini 上面的评论;除此之外,还需要改变高斯核生成的实现。
Gibara Canny 使用:
(g1 + g2 + g3) / 3f / (2f * (float) Math.PI * kernelRadius * kernelRadius)
中像素(+-0.5 像素)的平均值>(g1 + g2 + g3) / 3f 很好,但是单维方程下半部分的正确方差计算是:
(g1 + g2 + g3) / 3f / (Math. sqrt(2f * (float) Math.PI) * kernelRadius)
标准差
kernelRadius
是以下等式中的 sigma:单向高斯
我假设 Gibara 正在尝试根据以下方程实现二维高斯:二维高斯,其中卷积是每个高斯的直接乘积。虽然这可能是可能的并且更简洁,但以下代码将通过上述方差计算正确地在两个方向上进行卷积:
注意
yConv[]
现在是双向卷积,因此以下梯度 Sobel 计算如下如下所示:Gibara 非常简洁的非极大值抑制实现要求单独计算这些梯度,但是如果您想输出具有这些梯度的图像,可以使用欧几里德距离或曼哈顿距离对它们进行求和,欧几里德距离将如下所示
:有帮助,一切正常,并对我的代码表示歉意!欢迎批评指正
I've been spending some time with the Gibara Canny implementation and I'm inclined to agree with Settembrini's comment above; further to this one needs to change the implementation of the Gaussian Kernel generation.
The Gibara Canny uses:
(g1 + g2 + g3) / 3f / (2f * (float) Math.PI * kernelRadius * kernelRadius)
The averaging across a pixel (+-0.5 pixels) in
(g1 + g2 + g3) / 3f
is great, but the correct variance calculation on the bottom half of the equation for single dimensions is:(g1 + g2 + g3) / 3f / (Math.sqrt(2f * (float) Math.PI) * kernelRadius)
The standard deviation
kernelRadius
is sigma in the following equation:Single direction gaussian
I'm assuming that Gibara is attempting to implement the two dimensional gaussian from the following equation: Two dimensional gaussian where the convolution is a direct product of each gaussian. Whilst this is probably possible and more concise, the following code will correctly convolve in two directions with the above variance calculation:
NB the
yConv[]
is now the bidirectional convolution, so the following gradient Sobel calculations are as follows:Gibara's very neat implementation of non-maximum suppression requires that these gradients be calculated seperately, however if you want to output an image with these gradients one can sum them using either Euclidean or Manhattan distances, the Euclidean would look like so:
Hope this helps, is all in order and apologies for my code! Critique most welcome
除了 Favonius 的答案之外,您可能还想尝试 Greg 的 OpenCV 处理库,您现在可以轻松地使用它通过 Sketch > 安装导入库...>>添加库...并选择OpenCV进行处理
安装库后,您可以使用FindEdges 示例:
In addition to Favonius' answer, you might want to try Greg's OpenCV Processing library which you can now easily install via Sketch > Import Library... > Add Library... and select OpenCV for Processing
After you install the library, you can have a play with the FindEdges example:
正如我附注的那样。我前段时间研究了 Gibara Canny 的实现,发现了一些缺陷。例如,他在 x 和 y 方向上分离 1d 滤波器中的高斯滤波(这样就可以并且有效),但随后他不会应用这些滤波器的两遍(一个接一个),而只是将 SobelX 应用于 x-首轮高斯和 SobelY 到 y 首轮高斯,这当然会导致低质量梯度。因此,复制粘贴此类代码时要小心。
Just as I side note. I studied the Gibara Canny implementation some time ago and found some flaws. E.g. he separates the Gauss-Filtering in 1d filters in x and y direction (which is ok and efficient as such), but then he doesn't apply two passes of those filters (one after another) but just applies SobelX to the x-first-pass-Gauss and SobelY to the y-first-pass-Gauss, which of course leads to low quality gradients. Thus be careful just by copy-past such code.