Morphological operators that change the shape of particles process a pixel based on its number of neighbors and the values of those neighbors. A neighbor is a pixel whose value affects the values of nearby pixels during certain image processing functions. Morphological transformations use a 2D binary mask called a structuring element to define the size and effect of the neighborhood on each pixel, controlling the effect of the binary morphological functions on the shape and the boundary of a particle.

When to Use

Use a structuring element when you perform any primary binary morphology operation or the Separation advanced binary morphology operation. You can modify the size and the values of a structuring element to alter the shape of particles in a specific way. However, study the basic morphology operations before defining your own structuring element.

Concepts

The size and contents of a structuring element specify which pixels a morphological operation takes into account when determining the new value of the pixel being processed. A structuring element must have an odd-sized axis to accommodate a center pixel, which is the pixel being processed. The contents of the structuring element are always binary, composed of 1 and 0 values. The most common structuring element is a 3 × 3 matrix containing values of 1. This matrix, shown below, is the default structuring element for most binary and grayscale morphological transformations.

Three factors influence how a structuring element defines which pixels to process during a morphological transformation: the size of the structuring element, the values of the structuring element sectors, and the shape of the pixel frame.

Structuring Element Size

The size of a structuring element determines the size of the neighborhood surrounding the pixel being processed. The coordinates of the pixel being processed are determined as a function of the structuring element. In the following figure, the coordinates of the pixels being processed are (1, 1), (2, 2), and (3, 3), respectively. The origin (0, 0) is always the top, left corner pixel.

Using structuring elements requires an image border. A 3 × 3 structuring element requires a minimum border size of 1. In the same way, structuring elements of 5 × 5 and 7 × 7 require a minimum border size of 2 and 3, respectively. Bigger structuring elements require corresponding increases in the image border size.

Note Vision images have a default border size of 3. This border size enables you to use structuring elements as large as 7 × 7 without any modification. If you plan to use structuring elements larger than 7 × 7, specify a correspondingly larger border when creating your image.

The size of the structuring element determines the speed of the morphological transformation. The smaller the structuring element, the faster the transformation.

Structuring Element Values

The binary values of a structuring element determine which neighborhood pixels to consider during a transformation in the following manner:

  • If the value of a structuring element sector is 1, the value of the corresponding source image pixel affects the central pixel's value during a transformation.
  • If the value of a structuring element sector is 0, the morphological function disregards the value of the corresponding source image pixel.

The following figure illustrates the effect of structuring element values during a morphological function. A morphological transformation using a structuring element alters a pixel P0 so that it becomes a function of its neighboring pixel values.

Pixel Frame Shape

A digital image is a 2D array of pixels arranged in a rectangular grid. Morphological transformations that extract and alter the structure of particles allow you to process pixels in either a square or hexagonal configuration. These pixel configurations introduce the concept of a pixel frame. Pixel frames can either be aligned (square) or shifted (hexagonal). The pixel frame parameter is important for functions that alter the value of pixels according to the intensity values of their neighbors. Your decision to use a square or hexagonal frame affects how Vision analyzes the image when you process it with functions that use this frame concept. Vision uses the square frame by default.

Note Pixels in the image do not physically shift in a horizontal pixel frame. Functions that allow you to set the pixel frame shape merely process the pixel values differently when you specify a hexagonal frame.

The following figure illustrates the difference between a square and hexagonal pixel frame when a 3 × 3 and a 5 × 5 structuring element are applied.

If a morphological function uses a 3 × 3 structuring element and a hexagonal frame mode, the transformation does not consider the elements [2, 0] and [2, 2] when calculating the effect of the neighbors on the pixel being processed. If a morphological function uses a 5 × 5 structuring element and a hexagonal frame mode, the transformation does not consider the elements [0, 0], [4, 0], [4, 1], [4, 3], [0, 4], and [4, 4].

The following figure illustrates a morphological transformation using a 3 × 3 structuring element and a rectangular frame mode.

The following figure illustrates a morphological transformation using a 3 × 3 structuring element and a hexagonal frame mode.

The following table illustrates the effect of the pixel frame shape on a neighborhood given three structuring element sizes. The gray boxes indicate the neighbors of each black center pixel.

Square Frame

In a square frame, pixels line up normally. The following figure shows a pixel in a square frame surrounded by its eight neighbors. If d is the distance from the vertical and horizontal neighbors to the central pixel, then the diagonal neighbors are located at a distance of

2
d from the central pixel.

In a hexagonal frame, the even lines of an image shift half a pixel to the right. Therefore, the hexagonal frame places the pixels in a configuration similar to a true circle. The following figure shows a pixel in a hexagonal frame surrounded by its six neighbors. Each neighbor is an equal distance d from the central pixel, which results in highly precise morphological measurements.