Package com.openinventor.imageviz.engines.edgedetection.gradient

Introduction to Gradient

In the continuous 2-D case, the gradient of an image is defined along two orthogonal directions as:

This operator is approximated in the discrete case by differences, as initially introduced by Roberts:

along first and second diagonal directions.

These operators are implemented by convolutions with the kernels specified in Figure 1. They enhance edges in the {0,90} or {45,135} directions, respectively.

Figure 1: Roberts Gradient Edge Detectors In addition, one can define the magnitude and orientation of the gradient, as:

Note that when applying such filters to an image, the output images consist of positive and negative intensities, with an unusual appearance. The derivative operator behaves as a high frequency filter, i.e. it emphasizes details of an image. An immediate drawback of these gradient filters is their sensitivity to noise. When applied to grainy or textured images, the output image consists of high intensities which correspond to both true edges (luminance transitions), and noise (texture, grain aspect, etc.). This sensitivity to noise can be reduced by using larger kernels to approximate the derivative operators.

Typical masks, such as Prewitt or Sobel detectors for 3x3 kernels are given in Figure 2.

Figure 2: Prewitt and Sobel masks Another approach is to use morphological operators to estimate the gradient magnitude. We can then define morphological gradients as:

  • which marks the outer contours,
  • which marks the inner contours,
  • which marks contours of two-pixel widths for a 3x3 kernel B.

    is the result of a dilation with the neighborhood B, and the result of an erosion.

In , it can be shown that tends towards the gradient magnitude when B is a disk whose radius r tends towards 0.

Gradient detection

The output of the above gradients are gray level images, corresponding to emphasized edges in two orthogonal directions. The next step is to identify the pixels on these images which actually correspond to edge points. A common approach is to mark points of sufficiently large gradient magnitude, i.e. points where the luminance transition is sharp enough. This threshold of the gradient magnitude is illustrated in Figure 3.

Figure 3: Thresholding a gradient The overall detection scheme is outlined in Figure 4.

Figure 4: Gradient ComputationRemark: The normalization parameter enables to divide the value of the gradient by the sum of the absolute values of the masks, which reduces the noise sensitivity, avoids overflow, but lowers the contrast. Only main edges will appear on the gradient image. If no normalization is performed, be careful with possible overflow, but edges will be much more evident.