FUNCTION REFERENCE

bwmorph

Morphological operations on binary images.

Morphological operations on binary images.

Syntax

BW2 = bwmorph(BW, operation)

Syntax

BW2 = bwmorph(BW, operation, n)

Applies the operation n times (default 1; Inf repeats until the image stops changing) to the 2-D image BW (nonzero = foreground) and returns a logical image. Pixels outside the image are 0 except for erosion. Operations: 'remove' (sets a pixel to 0 when its four edge neighbours are all 1, leaving the boundary), 'clean' (removes isolated pixels without any of their 8 neighbours set), 'fill' (sets isolated 0s whose 8 neighbours are all 1), 'majority' (sets a pixel to 1 when 5 or more pixels of its 3-by-3 neighbourhood are 1, otherwise 0), 'dilate', 'erode', 'open', 'close' (with a 3-by-3 square), and 'thin' (the two-subiteration parallel thinning of Lam, Lee and Suen, 1992, p. 879; with n = Inf objects without holes become minimally connected strokes and objects with holes rings).

Example

bwmorph(logical([0 0 0; 0 1 0; 0 0 0]), 'clean')   % false(3)

Example

bwmorph(true(3), 'remove')   % [1 1 1; 1 0 1; 1 1 1]

Example

bwmorph(true(3, 5), 'thin', Inf)

Differences from MATLAB: 'skel', 'shrink', 'spur', 'endpoints', 'branchpoints', 'bridge', 'diag', 'hbreak', 'thicken', 'tophat' and 'bothat' are not supported yet. GNU Octave's 'fill' uses the four edge neighbours; MatRust follows the documented 8-neighbour wording.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.