## Documentation Center |

Find perimeter of objects in binary image

`BW2 = bwperim(BW1)BW2 = bwperim(BW1, conn)`

`BW2 = bwperim(BW1)` returns
a binary image containing only the perimeter pixels of objects in
the input image `BW1`. A pixel is part of the perimeter
if it is nonzero and it is connected to at least one zero-valued pixel.
The default connectivity is 4 for two dimensions, 6 for three dimensions,
and `conndef(ndims(BW), 'minimal')` for higher dimensions.

`BW2 = bwperim(BW1, conn)` specifies
the desired connectivity. `conn` can have any of
the following scalar values.

Value | Meaning |
---|---|

| |

4 | 4-connected neighborhood |

8 | 8-connected neighborhood |

| |

6 | 6-connected neighborhood |

18 | 18-connected neighborhood |

26 | 26-connected neighborhood |

Connectivity can also be defined in a more general way for any
dimension by using for `conn` a 3-by-3-by-...-by-3
matrix of `0`'s and `1`'s. The `1`-valued
elements define neighborhood locations relative to the center element
of `conn`. Note that `conn` must
be symmetric about its center element.

Find the perimeter of objects in an image mask.

BW1 = imread('circbw.tif'); BW2 = bwperim(BW1,8); imshow(BW1) figure, imshow(BW2)

`bwarea` | `bwboundaries` | `bweuler` | `bwtraceboundary` | `conndef` | `imfill`

Was this topic helpful?