Main Content

imdilate

Description

J = imdilate(I,SE) dilates the grayscale, binary, or packed binary image I using the structuring element SE.

example

J = imdilate(I,nhood) dilates the image I, where nhood is a matrix of 0s and 1s that specifies the structuring element neighborhood.

This syntax is equivalent to imdilate(I,strel(nhood)).

J = imdilate(___,packopt) specifies whether I is a packed binary image.

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

Examples

collapse all

Read a binary image into the workspace.

BW = imread("text.png");

Create a vertical line shaped structuring element.

se = strel("line",11,90);

Dilate the image with a vertical line structuring element.

BW2 = imdilate(BW,se);

Compare the original and dilated image.

imshow(BW)
title("Original")

Figure contains an axes object. The hidden axes object with title Original contains an object of type image.

imshow(BW2)
title("Dilated")

Figure contains an axes object. The hidden axes object with title Dilated contains an object of type image.

Read a grayscale image into the workspace.

originalI = imread("cameraman.tif");

Create a nonflat ball-shaped structuring element.

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

Dilate the image.

dilatedI = imdilate(originalI,se);

Display the original image and the dilated image.

imshowpair(originalI,dilatedI,"montage")

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

Create a logical 3-D volume with two points.

BW = false(100,100,100);
BW(25,25,25) = true;
BW(75,75,75) = true;

Dilate the 3D volume using a spherical structuring element.

se = strel("sphere",25);
dilatedBW = imdilate(BW,se);

Display the dilated image volume.

isosurface(dilatedBW,0.5)
axis equal

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

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 scalar strel object or offsetstrel object. SE can also be an array of strel object or offsetstrel objects, in which case imdilate performs multiple dilations of the input image, using each structuring element in succession.

imdilate performs grayscale dilation for all images except images of data type logical. In this case, the structuring element must be flat and imdilate performs binary dilation.

Structuring element neighborhood, specified as a matrix of 0s and 1s.

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

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

Value

Description

"notpacked"

I is treated as a normal array.

"ispacked"

I is treated as a packed binary image as produced by bwpack. I must be a 2-D uint32 array and SE must be a flat 2-D structuring element. The value of shape must be "same".

Data Types: char | string

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 of packopt is "ispacked", then shape must be "same".

"full"

Compute the full dilation.

Data Types: char | string

Output Arguments

collapse all

Dilated image, returned as a grayscale image, binary image, or packed binary image. If the input image I is packed binary, then J is also packed binary. J has the same data type as I.

More About

collapse all

Tips

  • If the dimensionality of the image I is greater than the dimensionality of the structuring element, then the imdilate function applies the same morphological dilation to all planes along the higher dimensions.

    You can use this behavior to perform morphological dilation 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, imdilate determines the center element of nhood by floor((size(nhood)+1)/2).

  • imdilate automatically takes advantage of the decomposition of a structuring element object (if it exists). Also, when performing binary dilation with a structuring element object that has a decomposition, imdilate automatically uses binary image packing to speed up the dilation [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 Processing 54, no. 3 (May 1, 1992): 252–58. https://doi.org/10.1016/1049-9652(92)90055-3.

Extended Capabilities

expand all

Version History

Introduced before R2006a

expand all