Main Content

bwmorph3

Morphological operations on binary volume

Description

example

J = bwmorph3(V,operation) applies a morphological operation to the binary volume V and returns the results of the operation in binary volume J.

Examples

collapse all

Load 3-D MRI volumetric data and create a binary volume. Use volshow to view the volumetric data with a gray color.

load mristack;
BW1 = mristack > 127;
cmap = [0.6 0.6 0.6];
volshow(BW1,Colormap=cmap);

To remove voxels that are set to 1 and that are also surrounded by voxels set to 0, perform the "clean" operation on the volumetric data. When determining which voxels to remove, the "clean" operation considers 26 neighboring voxels. Use volshow to view the results.

BW2 = bwmorph3(BW1,"clean");
volshow(BW2,Colormap=cmap);

For comparison, perform the "majority" operation on the volumetric data. The "majority" operation performs a similar task to the "clean" operation but only retains voxels if more than half (the majority) of the voxels in the neighborhood of the target voxel are set to 1. When determining which voxels to retain, the "majority" operation also considers 26 neighboring voxels. Use volshow to view the results.

BW3 = bwmorph3(BW1,"majority");
volshow(BW3,Colormap=cmap);

Input Arguments

collapse all

Input volume, specified as a numeric or logical array. For numeric input, any nonzero pixels are considered to be 1 (true).

bwmorph3 accepts 1-D, 2-D, or 3-D arrays. If you specify 1-D or 2-D input arrays, then bwmorph3 performs the morphological operation as defined for a 3-D volume. If you want 2-D behavior, use bwmorph instead.

Morphological operation to perform, specified as one of the following character vectors or string scalar.

Operation

Description

Illustration Before and After Processing

"branchpoints"

Find branch points of skeleton. Branch points are the voxels at the junction where multiple branches meet.

To find branch points, the image must be skeletonized. To create a skeletonized image, use bwskel.

The original image on the left is a chain of adjacent 1-valued voxels with two branches. The processed image on the right highlights the branch points in green and other voxels in red.

"clean"

Remove isolated voxels, setting them to 0. An isolated voxel is an individual, 26-connected voxel that is set to 1 that are surrounded by voxels set to 0.

The original image on the left is a chain of adjacent 1-valued voxels and one additional 1-valued voxel that does not touch any other voxels. The processed image on the right includes the chain and removes the isolated voxel.

"endpoints"

Find end points of skeleton. End points are voxels at the ends of branches.

Note: To find end points, the image must be skeletonized. To create a skeletonized image, use bwskel.

The original image on the left is a chain of adjacent 1-valued voxels with two branches. The processed image on the right highlights the four endpoints in green and other voxels in red.

"fill"

Fill isolated interior voxels (holes), setting them to 1. Isolated interior voxels are individual voxels that are set to 0 that are surrounded (6-connected) by voxels set to 1.

The original image on the left displays a hole, or a 0-valued voxel surrounded by 1-valued voxels on the top, bottom, left, right, front, and back. The processed image on the right fills the hole in the center with the value 1.

"majority"

Keep a voxel set to 1 if 14 or more voxels (the majority) in its 3-by-3-by-3, 26-connected neighborhood are set to 1; otherwise, set the voxel to 0.

The original image on the left displays a filled half sphere consisting of 1-valued voxels. The processed image on the right shows a filled half sphere with a smaller radius, which formed by removing the exterior shell of the original half sphere where voxels are not connected to a majority of their neighborhood.

"remove"

Remove interior voxels, setting it to 0. Interior voxels are individual voxels that are set to 1 that are surrounded (6-connected) by voxels set to 1.

The original image on the left is a volume consisting of a 1-valued voxel surrounded by 1-valued voxels on the top, bottom, left, right, front, and back. The processed image on the right shows a hole in the volume formed by setting the interior voxel to 0.

Data Types: char | string

Output Arguments

collapse all

Volume after morphological operations, returned as a logical array of the same size as input volume V.

Tips

  • To perform the morphological operations erosion or dilation on 3-D volumes, use the imerode or imdilate functions, specifying the structuring element ones(3,3,3).

  • To perform morphological closing, opening, top-hat filtering, or bottom-hat filtering on 3-D volumes, use the imclose, imopen, imtophat, or imbothat functions, specifying the structuring element ones(3,3,3).

Extended Capabilities

Version History

Introduced in R2018a

expand all