Main Content

imerode

Erode image

Description

example

J= imerode(I,SE)erodes the grayscale, binary, or packed binary imageIusing the structuring elementSE.

J= imerode(I,nhood)erodes the imageI, wherenhoodis a matrix of0s and1s that specifies the structuring element neighborhood.

This syntax is equivalent toimerode(I,strel(nhood)).

J= imerode(___,packopt,m)specifies whether input imageIis a packed binary image.mspecifies the row dimension of the original unpacked image.

J= imerode(___,shape)specifies the size of the output image.

Examples

collapse all

Read binary image into the workspace.

originalBW = imread('text.png');

Create a flat, line-shaped structuring element.

se = strel('line'90年,11日);

Erode the image with the structuring element.

erodedBW = imerode(originalBW,se);

View the original image and the eroded image.

figure imshow(originalBW)

Figure contains an axes object. The axes object contains an object of type image.

figure imshow(erodedBW)

Figure contains an axes object. The axes object contains an object of type image.

Read grayscale image into the workspace.

originalI = imread('cameraman.tif');

Create a nonflatoffsetstrelobject.

se = offsetstrel('ball',5,5);

Erode the image.

erodedI = imerode(originalI,se);

Display original image and eroded image.

figure imshow(originalI)

Figure contains an axes object. The axes object contains an object of type image.

figure imshow(erodedI)

Figure contains an axes object. The axes object contains an object of type image.

Create a binary volume.

loadmristackBW = mristack < 100;

Create a cubic structuring element.

se = strel('cube',3)
se = strel立方体形状的结构ring element with properties: Neighborhood: [3x3x3 logical] Dimensionality: 3

Erode the volume with a cubic structuring element.

erodedBW = imerode(BW, se);

Input Arguments

collapse all

Input image, specified as a grayscale image, binary image, or packed binary image of any dimension.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|logical

Structuring element, specified as a scalarstrelobject oroffsetstrelobject.SEcan also be an array ofstrelobject oroffsetstrelobjects, in which caseimerodeperforms multiple erosions of the input image, using each structuring element in succession.

imerodeperforms grayscale erosion for all images except images of data typelogical. In this case, the structuring element must be flat andimerodeperforms binary erosion.

Structuring element neighborhood, specified as a matrix of0s and1s.

Example:[0 1 0; 1 1 1; 0 1 0]

Indicator of packed binary image, specified as one of the following.

Value

Description

'notpacked'

Iis treated as a normal array.

'ispacked'

Iis treated as a packed binary image as produced bybwpack.Imust be a 2-Duint32array andSEmust be a flat 2-D structuring element. The value ofshapemust be'same'.

Data Types:char|string

Row dimension of the original unpacked image, specified as a positive integer.

Data Types:double

Size of the output image, specified as one of the following.

Value

Description

'same'

The output image is the same size as the input image. If the value ofpackoptis'ispacked',nshapemust be'same'.

'full'

Compute the full erosion.

Data Types:char|string

Output Arguments

collapse all

Eroded image, returned as a grayscale image, binary image, or packed binary image. If the input imageIis packed binary, thenJis also packed binary.Jhas the same data type asI.

More About

collapse all

Binary Erosion

Thebinary erosionofAbyB, denotedAϴB, is defined as the set operationAϴB= {z|(BzA}。换句话说,它是一组像素位置sz, where the structuring element translated to locationzoverlaps only with foreground pixels inA.

For more information on binary erosion, see[1].

Grayscale Erosion

In the general form ofgrayscale erosion,structuring element has a height. The grayscale erosion ofA(x,y)byB(x,y)is defined as:

(AϴB)(x,y) = min {A(x+x′,y+y′) −B(x′,y′) | (x′,y′) ∊DB},

DBis the domain of the structuring elementBandA(x,y)is assumed to be +∞ outside the domain of the image. To create a structuring element with nonzero height values, use the syntaxstrel(nhood,height), whereheightgives the height values andnhoodcorresponds to the structuring element domain,DB.

Most commonly, grayscale erosion is performed with a flat structuring element(B(x,y) = 0). Grayscale erosion using such a structuring element is equivalent to a local-minimum operator:

(AϴB)(x,y) = min {A(x+x′,y+y′) | (x′,y′) ∊DB}。

All of thestrelsyntaxes except forstrel(nhood,height),strel('arbitrary',nhood,height), andstrel('ball', ...)produce flat structuring elements.

Tips

  • If the dimensionality of the imageIis greater than the dimensionality of the structuring element, then theimerodefunction applies the same morphological erosion to all planes along the higher dimensions.

    You can use this behavior to perform morphological erosion on RGB images. Specify a 2-D structuring element for RGB images to operate on each color channel separately.

  • When you specify a structuring element neighborhood,imerodedetermines the center element ofnhoodbyfloor((size(nhood)+1)/2).

  • imerodeautomatically takes advantage of the decomposition of a structuring element object (if it exists). Also, when performing binary erosion with a structuring element object that has a decomposition,imerodeautomatically uses binary image packing to speed up the erosion[3].

References

[1]Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins.Digital Image Processing Using MATLAB. Third edition. Knoxville: Gatesmark Publishing, 2020.

[2]Haralick, Robert M., and Linda G. Shapiro.Computer and Robot Vision. 1st ed. USA: Addison-Wesley Longman Publishing Co., Inc., 1992, pp. 158-205.

[3]Boomgaard, Rein van den, and Richard van Balen. “Methods for Fast Morphological Image Transforms Using Bitmapped Binary Images.”CVGIP: Graphical Models and Image Processing54, no. 3 (May 1, 1992): 252–58. https://doi.org/10.1016/1049-9652(92)90055-3.

Extended Capabilities

Version History

Introduced before R2006a