Image Processing Toolbox    
bwmorph

Perform morphological operations on binary images

Syntax

Description

BW2 = bwmorph(BW1,operation) applies a specific morphological operation to the binary image BW1.

BW2 = bwmorph(BW1,operation,n) applies the operation n times. n can be Inf, in which case the operation is repeated until the image no longer changes.

operation is a string that can have one of the values listed below.

'bothat'
'erode'
'shrink'
'bridge'
'fill'
'skel'
'clean'
'hbreak'
'spur'
'close'
'majority'
'thicken'
'diag'
'open'
'thin'
'dilate'
'remove'
'tophat'

'bothat' ("bottom hat") performs morphological closing (dilation followed by erosion) and subtracts the original image.

'bridge' bridges previously unconnected pixels. For example,

'clean' removes isolated pixels (individual 1's that are surrounded by 0's), such as the center pixel in this pattern.

'close' performs morphological closing (dilation followed by erosion).

'diag' uses diagonal fill to eliminate 8-connectivity of the background. For example,

'dilate' performs dilation using the structuring element ones(3).

'erode' performs erosion using the structuring element ones(3).

'fill' fills isolated interior pixels (individual 0's that are surrounded by 1's), such as the center pixel in this pattern.

'hbreak' removes H-connected pixels. For example,

'majority' sets a pixel to 1 if five or more pixels in its 3-by-3 neighborhood are 1's; otherwise, it sets the pixel to 0.

'open' implements morphological opening (erosion followed by dilation).

'remove' removes interior pixels. This option sets a pixel to 0 if all of its 4-connected neighbors are 1, thus leaving only the boundary pixels on.

'shrink', with n = Inf, shrinks objects to points. It removes pixels so that objects without holes shrink to a point, and objects with holes shrink to a connected ring halfway between each hole and the outer boundary. This option preserves the Euler number.

'skel', with n = Inf, removes pixels on the boundaries of objects but does not allow objects to break apart. The pixels remaining make up the image skeleton. This option preserves the Euler number.

'spur' removes spur pixels. For example,

'thicken', with n = Inf, thickens objects by adding pixels to the exterior of objects until doing so would result in previously unconnected objects being 8-connected. This option preserves the Euler number.

'thin', with n = Inf, thins objects to lines. It removes pixels so that an object without holes shrinks to a minimally connected stroke, and an object with holes shrinks to a connected ring halfway between each hole and the outer boundary. This option preserves the Euler number.

'tophat' ("top hat") returns the image minus the morphological opening of the image.

Class Support

The input image BW1 can be numeric or logical. It must be 2-D, real and nonsparse. The output image BW2 is of class logical.

Example

See Also

bweuler, bwperim, dilate, erode

References

[1]  Haralick, Robert M., and Linda G. Shapiro. Computer and Robot Vision, Volume I. Addison-Wesley, 1992.

[2]  Pratt, William K. Digital Image Processing. John Wiley & Sons, Inc., 1991.


  bwlabeln bwpack