## ERODE

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.

### Calling Sequence

Result = ERODE( Image, Structure [, X 0 [, Y 0 [, Z 0 ]]] )

### Arguments

#### Image

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.

#### Structure

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 .

#### X 0 , Y 0 , Z 0

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.

### Keywords

#### GRAY

Set this keyword to perform grayscale, rather than binary, erosion. Nonzero elements of the Structure parameter determine the shape of the structuring element (neighborhood). If VALUES is not present, all elements of the structuring element are 0, yielding the neighborhood minimum operator.

#### VALUES

An array of the same dimensions as Structure providing the values of the structuring element. The presence of this keyword implies grayscale erosion. Each pixel of the result is the minimum of Image less the corresponding elements of VALUE.

### Example

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.

C = DILATE(ERODE(B, S), S) ; "Opening" operator.

TVSCL, C ; Show the result.