# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# strel class

Morphological structuring element

 Note:   To create the following nonflat structuring element shapes, use `offsetstrel` instead.`SE = strel('arbitrary',NHOOD,HEIGHT)``SE = strel('ball',R,H,N)`The following syntaxes still work, but are not recommended for use.`SE = strel('pair',OFFSET) ``SE = strel('periodicline',P,V)`

## Description

A `strel` object represents a flat morphological structuring element, which is an essential part of morphological dilation and erosion operations. (To create a nonflat structuring element, use `offsetstrel`.)

A flat structuring element is a binary valued neighborhood, either 2-D or multidimensional, in which the true pixels are included in the morphological computation, and the false pixels are not. The center pixel of the structuring element, called the origin, identifies the pixel in the image being processed. Use the `strel` function to create a flat structuring element. You can use flat structuring elements with both binary and grayscale images. The following figure illustrates a flat structuring element.

## Construction

````SE = strel('diamond',R)` creates a diamond-shaped structuring element, where `R` specifies the distance from the structuring element origin to the points of the diamond. ```

example

````SE = strel('disk',R,N)` creates a disk-shaped structuring element, where `R` specifies the radius. `N` specifies the number of line structuring elements used to approximate the disk shape. Morphological operations using disk approximations run much faster when the structuring element uses approximations.```

example

````SE = strel('line',len,deg)` creates a linear structuring element that is symmetric with respect to the neighborhood center. `deg` specifies the angle (in degrees) of the line as measured in a counterclockwise direction from the horizontal axis. `len` is approximately the distance between the centers of the structuring element members at opposite ends of the line.```
````SE = strel('octagon',R)` creates a octagonal structuring element, where `R` specifies the distance from the structuring element origin to the sides of the octagon, as measured along the horizontal and vertical axes. `R` must be a nonnegative multiple of 3.```
````SE = strel('rectangle',MN)` creates a rectangular structuring element, where `MN` specifies the size. ```

example

````SE = strel('square',W)` creates a square structuring element whose width is `W` pixels.```
````SE = strel('cube',W)` creates a cubic structuring element whose width is `W` pixels. `W` must be a nonnegative integer scalar.```
````SE = strel('cuboid',XYZ)` creates a cuboidal structuring element of size `XYZ`. ```

example

````SE = strel('sphere',R)` creates a spherical structuring element whose radius is `R` pixels.```

````SE = strel('arbitrary',nhood)` creates a structuring element, where `NHOOD` is a matrix of 1s and 0s that specifies the neighborhood. You can omit `'arbitrary'` and specify `strel(nhood)`.```

Code Generation support: Yes.

MATLAB Function Block support: Yes.

### Input Arguments

expand all

Radius of the structuring element in the X-Y plane, specified as a nonnegative integer.

For the disk shape, `R` is the distance from the origin to the edge of the disk.

For the diamond shape, `R` is the distance from the structuring element origin to the points of the diamond.

Data Types: `double`

Number of periodic line structuring elements used to approximate shape, specified as the scalar value 0, 4, 6, or 8. When `N` is greater than 0, the disk-shaped structuring element is approximated by a sequence of `N` periodic-line structuring elements. When N is 0, `strel` does no approximation, and the structuring element members comprise all pixels whose centers are no greater than `R` away from the origin. Morphological operations using disk approximations run much faster when the structuring element uses approximations `(N > 0)`. Sometimes it is necessary for `strel` to use two extra line structuring elements in the approximation, in which case the number of decomposed structuring elements used is `N + 2`.

Value of NBehavior
`N > 0``strel` uses a sequence of `N` (or sometimes `N+2`) periodic line-shaped structuring elements to approximate the shape.
`N = 0``strel` does not use any approximation. The structuring element members comprise all pixels whose centers are no greater than `R` away from the origin and the corresponding height values are determined from the formula of the ellipsoid specified by `R` and `H`.

Data Types: `double`

Size of rectangle-shaped structuring element, specified as a two-element vector of nonnegative integers. The first element of `MN` is the number of rows in the structuring element neighborhood and the second element is the number of columns.

Data Types: `double`

Width of square-shaped or cube-shaped structuring element, specified as a nonnegative integer scalar.

Data Types: `double`

Dimensions of cuboidal-shaped structuring element, specified as a three-element vector of nonnegative integers, of the form ```[X Y Z]```. `X` is the number of rows, `Y` is the number of columns, and `Z` is the number of planes in the third dimension.

Data Types: `double`

Neighborhood, specified as a matrix containing 1's and 0's. The location of the 1's defines the neighborhood for the morphological operation. The center (or origin) of `nhood` is its center element, given by `floor((size(nhood) + 1)/2)`.

Data Types: `double`

## Properties

expand all

Structuring element neighborhood, specified as a matrix of class `logical`.

Data Types: `logical`

Dimensions of structuring element, specified as a nonnegative scalar of class `double`.

Data Types: `double`

## Examples

expand all

Create an 11-by-11 square structuring element.

```SE = strel('square', 11) ```
```SE = strel is a square shaped structuring element with properties: Neighborhood: [11×11 logical] Dimensionality: 2 ```

Create a line-shaped structuring element with a length of 10 at an angle of 45 degrees.

```SE = strel('line', 10, 45) ```
```SE = strel is a line shaped structuring element with properties: Neighborhood: [7×7 logical] Dimensionality: 2 ```

View the structuring element.

```SE.Neighborhood ```
```ans = 7×7 logical array 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 ```

Create a disk-shaped structuring element with a radius of 15.

```SE3 = strel('disk', 15) ```
```SE3 = strel is a disk shaped structuring element with properties: Neighborhood: [29×29 logical] Dimensionality: 2 ```

Display the disk-shaped structuring element.

```figure imshow(SE3.Neighborhood) ```

Create a 3-D sphere-shaped structuring element with a radius of 15.

```SE = strel('sphere', 15) ```
```SE = strel is a sphere shaped structuring element with properties: Neighborhood: [31×31×31 logical] Dimensionality: 3 ```

Display the structuring element.

```figure isosurface(SE.Neighborhood) ```

## Tips

• Structuring elements that do not use approximations ```(N = 0)``` are not suitable for computing granulometries.

### Code Generation

This function supports the generation of C code using MATLAB® Coder™. For more information, see Code Generation for Image Processing.

When generating code, note the following:

• All input arguments must be compile-time constants.

• The methods associated with `strel` objects are not supported in code generation.

• Arrays of `strel` objects are not supported.

### MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

## Algorithms

For all shapes except `'arbitrary'`, structuring elements are constructed using a family of techniques known collectively as structuring element decomposition. The principle is that dilation by some large structuring elements can be computed faster by dilation with a sequence of smaller structuring elements. For example, dilation by an 11-by-11 square structuring element can be accomplished by dilating first with a 1-by-11 structuring element and then with an 11-by-1 structuring element. This results in a theoretical performance improvement of a factor of 5.5, although in practice the actual performance improvement is somewhat less. Structuring element decompositions used for the `'disk'` shape is an approximations—all other decompositions are exact.

## Methods

 decompose Return sequence of decomposed structuring elements reflect Reflect structuring element translate Translate structuring element

## References

[1] van den Boomgard, R, and R. van Balen, "Methods for Fast Morphological Image Transforms Using Bitmapped Images," Computer Vision, Graphics, and Image Processing: Graphical Models and Image Processing, Vol. 54, Number 3, pp. 252–254, May 1992.

[2] Adams, R., "Radial Decomposition of Discs and Spheres," Computer Vision, Graphics, and Image Processing: Graphical Models and Image Processing, Vol. 55, Number 5, pp. 325–332, September 1993.

[3] Jones, R., and P. Soille, "Periodic lines: Definition, cascades, and application to granulometrie," Pattern Recognition Letters, Vol. 17, pp. 1057–1063, 1996.