Matlab:关于梯度的一阶导数边缘检测 [英] Matlab: First derivative edge detection, about gradients

查看:900
本文介绍了Matlab:关于梯度的一阶导数边缘检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,要求用户在 Prewitt Sobel 图像过滤器之间进行选择检测图像对象的边缘。我必须使用他们的过滤器模板,而不是 edge 函数。用户还会告诉他是否要检测水平,垂直或对角线边缘。我的问题是理论问题,而不是编程问题。

I'm writing a program that asks the user to choose between Prewitt and Sobel image filters to detect edges of objects of an image. I must use their filter templates, not the edge function. The user also tells if he wants to detect 'horizontal', 'vertical' or 'diagonal' edges. My problem is theoretical rather than about programming.

在我的笔记中,我有计算每个像素的渐变幅度,它通常近似为 sqrt(Gx ^ 2 + Gy ^ 2)其中 Gx 将是垂直导数而 Gy 横向导数。但是如果我只计算水平边缘,那么 Gx 的值是多少?如果我只是在寻找垂直边缘,那么 Gy 的值是什么?

In my notes i've got that to compute the magnitude of the gradient at each pixel, it is often approximated as sqrt(Gx^2 + Gy^2) where Gx would be the vertical derivative and Gy the horizontal derivative. But what is the value of Gx if I only calculate the horizontal edges? And the value of Gy if I'm only looking for the vertical edges?

我无法猜到它我自己。

推荐答案

这很简单。您关心的是使用蒙版执行图像过滤,其中每个蒙版都是衍生过滤器。通过这种方法,knedlsepp是正确的,因为这样做只会找到关于给定方向的偏导数。您可以指定一个遮罩来检测水平边,另一个遮罩指示垂直边。

That's quite simple. What you are concerned about is performing an image filtering with masks, where each mask is a derivative filter. With this approach, knedlsepp is correct in that doing it this way would only find the partial derivatives with respect to a given direction. You would specify one mask to detect the horizontal and another for the vertical edges.

Gx 代表垂直边缘响应,使用垂直微分滤波器和 Gy 表示使用水平微分滤波器的水平边缘响应。要获得响应,您可以拍摄图像并使用任何蒙版的2D卷积对其进行过滤。

Gx stands for the vertical edge response by using a vertical derivative filter and Gy stands for the horizontal edge response by using a horizontal derivative filter. To get the responses, you would take your image and filter it by 2D convolution with any of the masks.

接下来,您将两个响应组合在一起以获得总体幅度响应。但是, edge 会在引擎盖下执行大量噪声清理,并执行阈值处理以获得最终响应。简单地计算幅度并不是 edge 的全部故事。

Next, you would combine both of the responses together to get the overall magnitude response. However, edge performs a lot of noise cleanup under the hood and also performs a thresholding to get the final response. Simply computing the magnitude is not the full story of what edge does.

无论如何,用于检测水平边缘,Prewitt面具看起来像这样:

In any case, for detecting horizontal edges, the Prewitt mask looks like so:

Gy_prewitt = 

-1    -1   -1
 0     0    0
 1     1    1

使用上述掩码执行过滤会发现水平边缘响应,或 Gy

Performing a filtering with the above mask finds the horizontal edge response, or Gy.

用于查找垂直边缘响应或 Gx ,你只需转置上面的掩码并找到过滤器响应,所以:

For finding the vertical edge response or Gx, you simply transpose the above mask and find the filter response, so:

Gx_prewitt =

     -1     0    1
     -1     0    1
     -1     0    1

Sobel面罩与Prewitt面罩略有不同。掩模的中心行(对于垂直)或列(对于水平)的中心行更夸张,并且加权两倍。水平掩码是:

The Sobel mask is slightly different than the Prewitt mask. There is more exaggeration on the central row of the mask (for the vertical) or column (for the horizontal) of the mask and is weighted by twice as much. The horizontal mask is:

Gy_sobel =

-1   -2   -1
 0    0    0
 1    2    1

同样,Sobel的垂直掩码定义为:

Similarly, the vertical mask for the Sobel is defined as:

Gx_sobel =

 -1     0    1
 -2     0    2
 -1     0    1

重要的是要注意掩码中所有系数的总和等于零,实际上是在实践中看到的任何边缘检测掩码的属性。

What is important to note is that the total sum of all coefficients in the mask equals to zero, and is actually a property of any edge detection mask seen in practice.

现在,为了确定整体边缘响应,你会对每个水平 Gy 和垂直 Gx 进行过滤响应,并对每个相应的像素应用幅度运算:

Now, to determine the overall edge response, you would take the filtering responses for each of the horizontal, Gy, and vertical Gx, and apply the magnitude operation per corresponding pixel:

out = sqrt(Gx.^2 + Gy.^2);






如果您想更直观地解释原因Sobel面具与Prewitt略有不同,我鼓励你看一下这篇文章。如果你不能使用内置的卷积方法,它提供了一个非常好的解释以及如何自己实现过滤操作的好图表:


If you want a more intuitive explanation as to why the Sobel mask is slightly different than the Prewitt, I encourage you to take a look at this post. It provides a very good explanation as well as a good diagram on how to implement the filtering operation yourself if you can't use built-in convolution methods:

http://blog.saush.com / 2011/04/20 / edge-detection-with-sobel-operator-in-ruby /

以下是图表:

基本上,对于要在图像中过滤的每个像素,提取一个3 x 3的邻域并在邻域中的像素和所需的过滤器之间执行加权和。在这种情况下,这将是Sobel垂直边缘检测器。

Basically, for each pixel you want to filter in your image, extract a 3 x 3 neighbourhood and perform a weighted sum between those pixels in the neighbourhood and the filter you want. In this case, this would be the Sobel vertical edge detector.

祝你好运!

这篇关于Matlab:关于梯度的一阶导数边缘检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆