For discrete digital images, the derivative in gradient operation
![$\displaystyle D_x[f(x)]=\frac{d}{dx}f(x)=\lim_{\Delta x \rightarrow 0}
\frac{f(x+\Delta x)-f(x)}{\Delta x}$](img43.svg) |
(20) |
becomes the difference
or![$\displaystyle \;\;\;\;
\frac{f[n+1]-f[n-1]}{2}$](img45.svg) |
(21) |
Two steps for finding discrete gradient of a digital image:
- Find the difference:
in the two directions:
![$\displaystyle g_m[m,n]=D_m[f[m,n]]=f[m+1,n]-f[m,n]$](img46.svg) |
(22) |
![$\displaystyle g_n[m,n]=D_n[f[m,n]]=f[m,n+1]-f[m,n]$](img47.svg) |
(23) |
- Find the magnitude and direction of the gradient vector:
or approximately![$\displaystyle \;\;\;\;\vert\vert g[m,n]\vert\vert=\vert\vert g_m\vert\vert+\vert\vert g_n\vert\vert$](img49.svg) |
(24) |
![$\displaystyle \angle g[m,n]=\tan^{-1} \left(\frac{g_n[m,n]}{g_m[m,n]}\right)$](img50.svg) |
(25) |
The differences in two directions
and
can be obtained by
convolution with the following kernels:
- Roberts
![$\displaystyle \left[ \begin{array}{rr} -1 & 1 \\ 0 & 0 \end{array} \right],
\;\;\;\;
\left[ \begin{array}{rr} -1 & 0 \\ 1 & 0 \end{array} \right]$](img53.svg) |
(26) |
or
![$\displaystyle \left[ \begin{array}{rr} 0 & 1 \\ -1 & 0 \end{array} \right],
\;\;\;\;
\left[ \begin{array}{rr} 1 & 0 \\ 0 & -1 \end{array} \right]$](img54.svg) |
(27) |
- Sobel (3x3)
![$\displaystyle \left[ \begin{array}{rrr} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1
...
...[ \begin{array}{rrr} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1
\end{array} \right]$](img55.svg) |
(28) |
- Prewitt (3x3)
![$\displaystyle \left[ \begin{array}{rrr} -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1
...
...[ \begin{array}{rrr} -1 & -1 & -1 \\ 0 & 0 & 0 \\ 1 & 1 & 1
\end{array} \right]$](img56.svg) |
(29) |
- Prewitt (4x4)
![$\displaystyle \left[ \begin{array}{rrrr} -3 & -1 & 1 & 3 \\ -3 & -1 & 1 & 3 \\ ...
... -3 \\ -1 & -1 & -1 & -1 \\
1 & 1 & 1 & 1 \\ 3 & 3 & 3 & 3 \end{array} \right]$](img57.svg) |
(30) |
Note Sobel and Prewitt operators first find the averages of one direction
and then find the difference of these averages in the another direction.