imclose

Morphologically close image

Syntax

J = imclose(I,SE)
J = imclose(I,nhood)

Description

example

J = imclose(I,SE) performs morphological closing on the grayscale or binary image I, returning the closed image, J. SE is a single structuring element object returned by the strel or offsetstrel functions. The morphological close operation is a dilation followed by an erosion, using the same structuring element for both operations.

You optionally can perform the morphological closing using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

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

Examples

collapse all

Read a binary image into the workspace and display it.

originalBW = imread('circles.png');
imshow(originalBW);

Create a disk-shaped structuring element. Use a disk structuring element to preserve the circular nature of the object. Specify a radius of 10 pixels so that the largest gap gets filled.

se = strel('disk',10);

Perform a morphological close operation on the image.

closeBW = imclose(originalBW,se);
figure, imshow(closeBW)

Use morphological closing to join the circles in an image together by filling in the gaps between them and by smoothing their outer edges.

Read the image into the workspace and view it.

originalBW = imread('circles.png');
imshow(originalBW);

Create a disk-shaped structuring element. Use a disk structuring element to preserve the circular nature of the object. Specify a radius of 10 pixels so that the largest gap gets filled.

se = strel('disk',10);

Perform a morphological close operation on the image on a GPU.

closeBW = imclose(gpuArray(originalBW),se);
figure
imshow(closeBW)

Input Arguments

collapse all

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

To perform the closing using a GPU, specify I as a gpuArray that contains an image of type uint8 or logical.

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

Structuring element, specified as a single strel object or offsetstrel object. If the image I is data type logical, then the structuring element must be flat.

If you perform the closing using a GPU, then SE must be flat and two-dimensional.

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

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

Output Arguments

collapse all

Closed image, returned as a grayscale image or binary image. J has the same class as input image I.

If the closing is performed using a GPU, then J is returned as a gpuArray that contains a grayscale or binary image of the same class as I.

Compatibility Considerations

expand all

Behavior changed in R2017a

Extended Capabilities

See Also

Functions

Objects

Introduced before R2006a