Image derivatives can be computed by using small convolution filters of size 2 × 2 or 3 × 3, such as the Laplacian, Sobel, Roberts and Prewitt operators.[1] However, a larger mask will generally give a better approximation of the derivative and examples of such filters are Gaussian derivatives[2] and Gabor filters.[3] Sometimes high frequency noise needs to be removed and this can be incorporated in the filter so that the Gaussian kernel will act as a band pass filter.[4] The use of Gabor filters[5] in image processing has been motivated by some of its similarities to the perception in the human visual system.[6]
The pixel value is computed as a convolution
p'u=d\astG
d
G
\ast
The derivative kernels, known as the Sobel operator are defined as follows, for the
u
v
p'u=\begin{bmatrix} +1&+2&+1\\ 0&0&0\\ -1&-2&-1 \end{bmatrix}*G and p'v=\begin{bmatrix} +1&0&-1\\ +2&0&-2\\ +1&0&-1 \end{bmatrix}*G
where
*
This operator is separable and can be decomposed as the products of an interpolation and a differentiationkernel, so that,
p'v
\begin{bmatrix} +1&0&-1\\ +2&0&-2\\ +1&0&-1 \end{bmatrix} = \begin{bmatrix} 1\\ 2\\ 1 \end{bmatrix} \begin{bmatrix} +1&0&-1 \end{bmatrix}
Farid and Simoncelli[7] [8] propose to use a pair of kernels, one for interpolation and another for differentiation (compare to Sobel above). These kernels, of fixed sizes 5 x 5 and 7 x 7, are optimized so that the Fourier transform approximates their correct derivative relationship.
In Matlab code the so called 5-tap filter is
As an example the first order derivatives can be computed in the following using Matlab in order to perform the convolution
It is noted that Farid and Simoncelli have derived first derivative coefficients which are more accurate compared to the ones provided above. However, the latter are consistent with the second derivative interpolator and, therefore, are better to use if both the first and second derivatives are sought. In the opposite case, when only the first derivative is desired, the optimal first derivative coefficients should be employed; more details can be found in their paper.
Derivative filters based on arbitrary cubic splines was presented by Hast.[9] He showed how both first and second order derivatives can be computed more correctly using cubic or trigonometric splines. Efficient derivative filters need to be of odd length so that the derivative is computed for the central pixel. However, any cubic filter is fitted over 4 sample points, giving a centre that falls between pixels. This is solved by a double filtering approach giving filters of size 7 x 7. The idea is to first filter by interpolation so that the interpolated value between pixels are obtained, whereafter the procedure is repeated using a derivative filters, where the centre value now falls on pixel centres. This can easily be proved by the associative law for convolution
p'u=d\ast(k\astG)=(d\astk)\astG
kd |
k
d
kd=d |
\astk
Also keep in mind that convolution is commutative, so that the order of the two kernels does not matter and it is also possible to insert a second order derivative as well as a first order derivative kernel. These kernels are derived from the fact that any spline surface can be fitted over a square pixel region, compare to Bezier surfaces. Hast proves that such a surface can be performed as a separable convolution
p(u,v)=uTMGMTv=MTu ⊗ vTM\astG
where
M
u
v
u
v
u=[u3,u2,u,1]T
v=[v3,v2,v,1]T
k=uTM=(MTv)T
d= | \partialuT |
\partialu |
M=\left(MT
\partialv | |
\partialv |
\right)T
d2= | \partial2uT |
\partialu2 |
M=\left(MT
\partial2v | |
\partialv2 |
\right)T
The first order derivatives at the central pixel are hence computed as
D | ||||
|
M\astuTMGMTv\astMTv=d\astk ⊗ (k\astk)T\astG
T | |
D | |
v=u |
M\astuTMGMTv\astMT
\partialv | |
\partialv |
=k\astk ⊗ (d\astk)T\astG
Likewise, with the second order derivative kernels are
2 | ||||
D | ||||
|
M\astuTMGMTv\astMTv=
d2 |
\astk ⊗ (k\astk)T\astG
T | |
D | |
v=u |
M\astuTMGMTv\astMT
\partial2v | |
\partialv2 |
=k\astk ⊗
(d2 |
\astk)T\astG
The cubic spline filter is evaluated in its centre
u=v=0.5
u=v=[(0.5)3,(0.5)2,0.5,1]T=[0.125,0.25,0.5,1]T
\partialu(0.5) | = | |
\partialu |
\partialv(0.5) | |
\partialv |
=[3 ⋅ (0.5)2,2 ⋅ (0.5),1,0]T=[0.75,1,1,0]T
d2u(0.5) | = | |
u2 |
d2v(0.5) | |
dv2 |
=[6 ⋅ (0.5),2,0,0]T=[3,2,0,0]T
Any cubic filter can be applied and used for computing the image derivates using the above equations, such as Bézier, Hermite or B-splines.
The example in below in Matlab use the Catmull-Rom spline to compute the derivatives
Steerable filters can be used for computing derivatives[10] Moreover, Savitzky and Golay[11] propose a least-squares polynomial smoothing approach, which could be used for computing derivatives and Luo et al[12] discuss this approach in further detail. Scharr[13] [14] [15] shows how to create derivative filters by minimizing the error in the Fourier domain and Jähne et al[16] discuss in more detail the principles of filter design, including derivative filters.