Gradients and Sobel Derivatives
One of the most basic and important convolutions is the computation of derivatives (or approximations to them). There are many ways to do this, but only a few are well suited to a given situation.
In general, the most common operator used to represent differentiation is the Sobel derivative [Sobel68] operator (see Figures Figure 6-3 and Figure 6-4). Sobel operators exist for any order of derivative as well as for mixed partial derivatives (e.g.,

).

Figure 6-3. The effect of the Sobel operator when used to approximate a first derivative in the x-dimension
cvSobel(
const CvArr* src,
CvArr* dst,
int xorder,
int yorder,
int aperture_size = 3
);Here, src and dst
are your image input and output, and xorder and yorder are the orders of the derivative. Typically you'll use 0,
1, or at most 2; a 0 value indicates no derivative in that direction. [65] The aperture_size parameter should be odd and
is the width (and the height) of the square filter. Currently, aperture sizes of 1, 3, 5,
and 7 are supported. If src is 8-bit then the dst must be of depth IPL_DEPTH_16S to avoid overflow.

Figure 6-4. The effect of the Sobel operator when used to approximate a first derivative ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access