为什么 Sobel 算子看起来那样? [英] Why Sobel operator looks that way?

查看:28
本文介绍了为什么 Sobel 算子看起来那样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于图像导数计算,Sobel 算子是这样的:

For image derivative computation, Sobel operator looks this way:

[-1 0 1]
[-2 0 2]
[-1 0 1]

我不太了解它的两件事,

I don't quite understand 2 things about it,

1.为什么中心像素是0?我不能只使用像下面这样的运算符吗,

1.Why the centre pixel is 0? Can't I just use an operator like below,

[-1 1]
[-1 1]
[-1 1]

2.为什么中间行是其他行的2倍?

2.Why the centre row is 2 times the other rows?

我用谷歌搜索了我的问题,没有找到任何可以说服我的答案.请帮帮我.

I googled my questions, didn't find any answer which can convince me. Please help me.

推荐答案

在计算机视觉中,通常没有完美、通用的做事方式.大多数情况下,我们只是尝试一个运算符,查看其结果并检查它们是否符合我们的需求.梯度计算也是如此:Sobel 算子是计算图像梯度的众多方法之一,已在许多用例中证明了其有用性.

In computer vision, there's very often no perfect, universal way of doing something. Most often, we just try an operator, see its results and check whether they fit our needs. It's true for gradient computation too: Sobel operator is one of many ways of computing an image gradient, which has proved its usefulness in many usecases.

事实上,我们能想到的更简单的梯度算子比你上面建议的更简单:

In fact, the simpler gradient operator we could think of is even simpler than the one you suggest above:

[-1 1]

尽管它很简单,但该运算符有第一个问题:当您使用它时,您计算的是 两个位置之间的梯度,而不是 一个位置的梯度.如果将其应用于 2 个像素 (x,y)(x+1,y),您是否计算了位置 (x,y) 处的梯度 还是 (x+1,y)?实际上,您计算的是位置 (x+0.5,y) 处的梯度,使用半像素不是很方便.这就是我们在中间加一个零的原因:

Despite its simplicity, this operator has a first problem: when you use it, you compute the gradient between two positions and not at one position. If you apply it to 2 pixels (x,y) and (x+1,y), have you computed the gradient at position (x,y) or (x+1,y)? In fact, what you have computed is the gradient at position (x+0.5,y), and working with half pixels is not very handy. That's why we add a zero in the middle:

[-1 0 1]

将此应用于像素 (x-1,y)(x,y)(x+1,y)将清楚地为您提供中心像素 (x,y) 的渐变.

Applying this one to pixels (x-1,y), (x,y) and (x+1,y) will clearly give you a gradient for the center pixel (x,y).

这也可以看作是两个 [-1 1] 过滤器的卷积:[-1 1 0] 计算位置 处的梯度(x-0.5,y),在像素的左边,[0 -1 1],在像素的右边计算梯度.

This one can also be seen as the convolution of two [-1 1] filters: [-1 1 0] that computes the gradient at position (x-0.5,y), at the left of the pixel, and [0 -1 1] that computes the gradient at the right of the pixel.

现在这个过滤器还有另一个缺点:它对噪音非常敏感.这就是为什么我们决定不将其应用于单行像素,而是应用于 3 行:这允许在这 3 行上获得平均梯度,这将软化可能的噪声:

Now this filter still has another disadvantage: it's very sensitive to noise. That's why we decide not to apply it on a single row of pixels, but on 3 rows: this allows to get an average gradient on these 3 rows, that will soften possible noise:

[-1 0 1]
[-1 0 1]
[-1 0 1]

但是这个往往过于平均化:当应用于一个特定的行时,我们失去了这个特定行的大部分细节.为了解决这个问题,我们想给中间行增加一点权重,这将使我们能够通过考虑前一行和下一行中发生的情况来消除可能的噪音,但仍然保持该行的特异性.这就是 Sobel 过滤器的原因:

But this one tends to average things a little too much: when applied to one specific row, we lose much of what makes the detail of this specific row. To fix that, we want to give a little more weight to the center row, which will allow us to get rid of possible noise by taking into account what happens in the previous and next rows, but still keeping the specificity of that very row. That's what gives the Sobel filter:

[-1 0 1]
[-2 0 2]
[-1 0 1]

篡改系数可能会导致其他梯度算子,例如 Scharr 算子,它只是增加了一点中间行的权重:

Tampering with the coefficients can lead to other gradient operators such as the Scharr operator, which gives just a little more weight to the center row:

[-3  0 3 ]
[-10 0 10]
[-3  0 3 ]

这也有数学原因,例如这些过滤器的可分离性...但我更喜欢将其视为一个实验发现,它被证明具有有趣的数学特性,因为实验在我的意见是计算机视觉的核心.只有您的想象力是创造新事物的极限,只要它符合您的需求......

There are also mathematical reasons to this, such as the separability of these filters... but I prefer seeing it as an experimental discovery which proved to have interesting mathematical properties, as experiment is in my opinion at the heart of computer vision. Only your imagination is the limit to create new ones, as long as it fits your needs...

这篇关于为什么 Sobel 算子看起来那样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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