The ERODE function implements the erosion operator on binary and grayscale images and vectors.

See the description of the DILATE function for background on morphological operators. Erosion is the dual of dilation. It does to the background what dilation does to the foreground.

Briefly, the ERODE function returns the erosion of *
Image*
by the structuring element *
Structure*
. This operator is commonly known as "
shrink" or "
reduce". It can be used to remove islands smaller than the structuring element.

Over each pixel of the image, the origin of the structuring element is overlaid. If each nonzero element of the structuring element is contained in the image, the output pixel is set to one. Letting *
A*
*
*
*
B*
represent the erosion of an image *
A*
by structuring element *
B*
, erosion can be defined as:

where *
(A)*
_{
-b}
represents the translation of *
A*
by *
b*
. The structuring element *
B*
can be visualized as a probe that slides across image *
A*
, testing the spatial nature of *
A*
at each point. If *
B*
translated by *
i,j*
can be contained in *
A*
(by placing the origin of *
B*
at *
i,j*
), then *
i,j*
belongs to the erosion of *
A*
by *
B*
. For example:

In this example, the origin of the structuring element is at (0, 0).

Used with grayscale images, which are always converted to byte type, the ERODE function is accomplished by taking the minimum of a set of differences. It can be used to conveniently implement the neighborhood minimum operator with the shape of the neighborhood given by the structuring element.

A one-, two-, or three-dimensional array upon which the erosion is to be performed. If this parameter is not of byte type, a temporary byte copy is obtained. If neither of the keywords GRAY or VALUES is present, the image is treated as a binary image with all nonzero pixels considered as 1.

A one-, two-, or three-dimensional array to be used as the structuring element. The elements are interpreted as binary values--either zero or nonzero. The structuring element must have the same number of dimensions as *
Image*
.

Optional parameters specifying the one-, two-, or three-dimensional coordinate of the structuring element's origin. If omitted, the origin is set to the center, ([*
N*
_{
x}
/2], [*
N*
_{
y}
/2], [*
N*
_{
z}
/2]), where *
N*
_{
x}
, *
N*
_{
y}
, and *
N*
_{
z}
are the dimensions of the structuring element array. The origin need not be within the structuring element.

The following example thresholds a gray scale image at the value of 100, producing a binary image. The result is then "opened" with a 3 pixel by 3 pixel square shape operator, using the ERODE and DILATE operators. The effect is to remove holes, islands, and peninsula smaller than the shape operator:

B = A GE 100 *;
Threshold and make binary image.*

S = REPLICATE(1, 3, 3) *;
Create the shape operator.*