J = imdilate(I,SE)
J = imdilate(I,nhood)
J = imdilate(___,packopt)
J = imdilate(___,shape)
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 and compare the results.
BW2 = imdilate(BW,se); imshow(BW), title('Original')
figure, imshow(BW2), title('Dilated')
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.
Create two flat, line-shaped structuring elements, one at 0 degrees and the other at 90 degrees.
se1 = strel('line',3,0)
se1 = strel is a line shaped structuring element with properties: Neighborhood: [1 1 1] Dimensionality: 2
se2 = strel('line',3,90)
se2 = strel is a line shaped structuring element with properties: Neighborhood: [3x1 logical] Dimensionality: 2
Dilate the scalar value 1 with both structuring elements in sequence, using the
composition = imdilate(1,[se1 se2],'full')
composition = 3×3 1 1 1 1 1 1 1 1 1
Create a logical 3D 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);
Visualize the dilated image volume.
figure isosurface(dilatedBW, 0.5)
I— Input image
Input image, specified as a grayscale image, binary image, or packed binary image of any dimension.
To perform the dilation using a GPU, specify
I as a
gpuArray that contains an
image of type
SE— Structuring element
offsetstrelobject | array of
strelobjects | array of
Structuring element, specified as a scalar
strel object or
SE can also be an array of
strel object or
offsetstrel objects, in which
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
If you perform the dilation using a GPU, then
be flat and two-dimensional.
nhood— Structuring element neighborhood
Structuring element neighborhood, specified as a matrix of 0s and 1s.
[0 1 0; 1 1 1; 0 1 0]
packopt— Indicator of packed binary image
Indicator of packed binary image, specified as one of the following.
packopt argument is not supported on a
shape— Size of output image
Size of the output image, specified as one of the following.
The output image is the same size as the input
image. If the value of
Compute the full dilation.
J— Dilated image
Dilated image, returned as a grayscale image, binary image, or packed
binary image. If the input image
I is packed binary,
J is also packed binary.
has the same class as
If the dilation is performed using a GPU, then
returned as a
gpuArray that contains a
grayscale or binary image of the same class as
The binary dilation of A by B, denoted A ⨁ B, is defined as the set operation:
where is the reflection of the structuring element B. In other words, it is the set of pixel locations z, where the reflected structuring element overlaps with foreground pixels in A when translated to z. Note that some applications use a definition of dilation in which the structuring element is not reflected.
For more information about binary dilation, see .
In the general form of grayscale dilation, the structuring element has a height. The grayscale dilation of A(x, y) by B(x, y) is defined as:
where DB is the domain
of the structuring element B and A(x,
y) is assumed to be –∞ outside the domain of the image. To create a
structuring element with nonzero height values, use the syntax
the height values and
nhood corresponds to the structuring
element domain, DB.
Most commonly, grayscale dilation is performed with a flat structuring element (B(x,y) = 0). Grayscale dilation using such a structuring element is equivalent to a local-maximum operator:
All of the
strel syntaxes except for
...) produce flat structuring elements.
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,
automatically uses binary image packing to speed up the dilation.
Dilation using bit packing is described in .
 Gonzalez, R. C., R. E. Woods, and S. L. Eddins, Digital Image Processing Using MATLAB, Gatesmark Publishing, 2009.
 Haralick, R. M., and L. G. Shapiro, Computer and Robot Vision, Vol. I, Addison-Wesley, 1992, pp. 158-205.
 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. 254-258, May 1992.
Usage notes and limitations:
imdilate supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic
MATLAB Host Computer
imdilate generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.
The input image,
I, must be 2-D or 3-D.
The structuring element argument
SE must be a
single element—arrays of structuring elements are not supported.
To obtain the same result as that obtained using an array of structuring
elements, call the function sequentially.
When the target is
MATLAB Host Computer, the
arguments must be compile-time constants. When the target is any other
packopt syntax is not
Usage notes and limitations:
gpuArray input must be of type
logical and the structuring element
SE must be flat and two-dimensional.
packopt argument is not supported on the
For more information, see Image Processing on a GPU.