# bwmorph3

Morphological operations on binary volume

## Syntax

``J = bwmorph3(V,operation)``

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

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

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

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

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

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

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

## Version History

Introduced in R2018a

expand all