Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

imdilate

Syntax

J = imdilate(I,SE)
J = imdilate(I,nhood)
J = imdilate(___,packopt)
J = imdilate(___,shape)
gpuarrayJ = imdilate(gpuarrayI,___)

Description

example

J = imdilate(I,SE) dilates the grayscale, binary, or packed binary image I, returning the dilated image, J. SE is a structuring element object or array of structuring element objects, returned by the strel or offsetstrel functions.

J = imdilate(I,nhood) dilates the image I, where nhood is a matrix of 0s and 1s that specifies the structuring element neighborhood. This is equivalent to the syntax imdilate(I,strel(nhood)). The imdilate function determines the center element of the neighborhood by floor((size(nhood)+1)/2).

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

example

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

example

gpuarrayJ = imdilate(gpuarrayI,___) dilates an image, using a GPU. The packopt argument is not supported on a GPU. This syntax requires Parallel Computing Toolbox™.

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 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.

imshowpair(originalI,dilatedI,'montage')

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 'full' option.

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)

Read a binary image.

 originalBW = imread('text.png');

Create a structuring element.

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

Dilate the image with a vertical line structuring element and compare the results. Note how the example passes the image to the gpuArray function as it passes it to imdilate.

dilatedBW = imdilate(gpuArray(originalBW),se);
imshowpair(originalBW,dilatedBW,'montage')

Read a grayscale image.

 originalI = imread('cameraman.tif');

Create a structuring element.

 se = strel('disk',5);

Dilate a grayscale image with a rolling ball structuring element.

dilatedI = imdilate(gpuArray(originalI),se);
imshowpair(originalI,dilatedI,'montage')

Input Arguments

collapse all

Input image, specified as a grayscale image, binary image, or packed binary image. I can have any dimension, and must be real and nonsparse.

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'.

Note

The packopt argument is not supported on a GPU.

Data Types: char | string

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

Value

Description

'same'

The output image the same size as the input image. If the value of packopt is 'ispacked', shape must be 'same'.

'full'

Compute the full dilation.

Data Types: char | string

Image to be dilated on a GPU, specified as a gpuArray containing an image of type uint8 or logical. The structuring element SE must be flat and two-dimensional.

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 class as I.

Dilated image when run on a GPU, returned as a gpuArray. The output gpuarrayJ has the same class as the input gpuarrayI.

More About

collapse all

Binary Dilation

The binary dilation of A by B, denoted AB, is defined as the set operation:

AB={z|(B^)zA},

where B^ 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 people use a definition of dilation in which the structuring element is not reflected.

For more information about binary dilation, see [1].

Grayscale Dilation

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:

(AB)(x,y)=max{A(xx,yy)+B(x,y)|(x,y)DB},

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 strel(nhood,height), where height gives 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:

(AB)(x,y)=max{A(xx,yy)|(x,y)DB}.

All of the strel syntaxes except for strel(nhood,height), strel('arbitrary',nhood,height), and strel('ball', ...) produce flat structuring elements.

Algorithms

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.

Dilation using bit packing is described in [3].

References

[1] Gonzalez, R. C., R. E. Woods, and S. L. Eddins, Digital Image Processing Using MATLAB, Gatesmark Publishing, 2009.

[2] Haralick, R. M., and L. G. Shapiro, Computer and Robot Vision, Vol. I, Addison-Wesley, 1992, pp. 158-205.

[3] 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.

Extended Capabilities

See Also

Functions

Objects

Introduced before R2006a

Was this topic helpful?