关于图形学中图像的一阶导数和二阶导数求法

对于图像求一阶导数和二阶导数可以增强图片或者求图像的边缘。

一阶导数:

我们知道在数学中一阶导数的求法为:

                                                                             \frac{\partial f}{\partial x} = \lim_{x\rightarrow 0} \frac{f(x+h)-f(x)}{h}

在图形学中由于图片是按像素来离散组成的,所以最小的h取值为1,所以计算后:

                                                                           \frac{\partial f}{\partial x}=f(x+1)-f(x)

所以图像的一阶导数就是图像亮度的变化率,对于一个灰度图像,他的一阶导数计算如下:

灰度图像矩阵:
a b c
d e f
g h i
那么对于中心像素e:
dx=f-e(或者f-d)
dy=h-e(或者h-i)
当然如果用sobel算子的话
dx=(c+2f+i)-(a+2d+g)
dy=(g+2h+i)-(a+2b+c)

所以在图像边缘检测中,sobel算子的卷积因子为:

可以看出这个卷积因子其实就是sobel算子求图像一阶导数。

二阶导数:

                                                                \frac{\partial^2f}{\partial x ^2}=\frac{ f'(x+h)-f'(x)}{h}

所以当h=1时:

                                                                 \frac{\partial^2f}{\partial x ^2}=f'(x+1)-f'(x)

这时可以化简:

\frac{\partial^2f}{\partial x ^2}=\frac{\partial f'(x)}{dx^2}=f'(x+1)-f'(x)

=f((x+1)+1)-f((x+1))-(f(x+1)-f(x))

=f(x+2)-f(x+1)-f(x+1)+f(x)

=f(x+2)-2f(x+1)+f(x)

这一步在数学中推导为(数学差的我看了一上午才看懂):

令x=x-1 
则: 

\frac{\partial^2f}{\partial x ^2}=f(x+1)+f(x-1)-2f(x)

在x和y方向上,有: 

\frac{\partial^2f}{\partial x ^2}=f(x+1,y)+f(x-1,y)-2f(x,y)

\frac{\partial^2f}{\partial y ^2}=f(x,y+1)+f(x,y-1)-2f(x,y)

把x方向和y方向的二阶导数结合在一起:

\frac{\partial^2f}{\partial x ^2}+\frac{\partial^2f}{\partial y ^2}=f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)-4f(x,y)

这实质上就是著名的拉普拉斯二阶微分算子(Laplacian),拉普拉斯二阶导数还有其它的形式,例如:

Laplacian = 4f(x,y)-f(x+1,y)-f(x-1,y)-f(x,y+1)-f(x,y-1)

所以 Laplacian算子的卷积因子有以下两种:

猜你喜欢

转载自blog.csdn.net/qq_40238526/article/details/89840463