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 ...