Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

bwperim

Find perimeter of objects in binary image

Syntax

BW2 = bwperim(BW)
BW2 = bwperim(BW,conn)

Description

example

BW2 = bwperim(BW) returns a binary image that contains only the perimeter pixels of objects in the input image BW. 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. If you do not specify a return value, bwperim displays the result in a figure window.

BW2 = bwperim(BW,conn) where conn specifies the desired connectivity.

Examples

collapse all

Read binary image into workspace.

BW = imread('circles.png');

Calculate the perimeters of objects in the image.

BW2 = bwperim(BW,8);

Display the original image and the perimeters side-by-side.

imshowpair(BW,BW2,'montage')

Input Arguments

collapse all

Input binary image, specified as a logical or numeric matrix that must be 2-D, real, and nonsparse.

Example: BW = imread('circles.png'); BW2 = bwperim(BW);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Connectivity, specified as one of the values in this table or a 3-by-3-by-...-by-3 array of 0s and 1s. The 1-valued elements define neighborhood locations relative to the center element of conn. Note that conn must be symmetric around its center element.

Value

Meaning

Two-dimensional connectivities

4

4-connected neighborhood

8

8-connected neighborhood

Three-dimensional connectivities

6

6-connected neighborhood

18

18-connected neighborhood

26

26-connected neighborhood

Example: BW2 = bwperim(BW,8);

Data Types: double | logical

Output Arguments

collapse all

Output image containing only perimeter pixels of objects, returned as a logical array.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?