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.
BW2 = bwperim(BW,conn)
specifies the pixel connectivity, conn.
Pixel connectivity, specified as one of the values in this table. The
default connectivity is 4 for 2-D images, and
6 for 3-D images.
Value
Meaning
Two-Dimensional Connectivities
4-connected
Pixels are connected if their edges touch. Two adjoining pixels are
part of the same object if they are both on and are connected along the
horizontal or vertical direction.
8-connected
Pixels are connected if their edges or corners touch. Two adjoining
pixels are part of the same object if they are both on and are connected
along the horizontal, vertical, or diagonal direction.
Three-Dimensional Connectivities
6-connected
Pixels are connected if their faces touch. Two adjoining pixels are
part of the same object if they are both on and are connected in:
One of these directions: in, out, left, right, up, and
down
18-connected
Pixels are connected if their faces or edges touch. Two adjoining
pixels are part of the same object if they are both on and are connected in
One of these directions: in, out, left, right, up, and
down
A combination of two directions, such as right-down or
in-up
26-connected
Pixels are connected if their faces, edges, or corners touch. Two
adjoining pixels are part of the same object if they are both on and are
connected in
One of these directions: in, out, left, right, up, and
down
A combination of two directions, such as right-down or
in-up
A combination of three directions, such as in-right-up or
in-left-down
For higher dimensions, bwperim uses the default value
conndef(ndims(BW),'minimal').
Connectivity can also be
defined in a more general way for any dimension by specifying a 3-by-3-by- ... -by-3 matrix of
0s and 1s. The 1-valued elements
define neighborhood locations relative to the center element of conn. Note
that conn must be symmetric about its center element. See Specifying Custom Connectivities for more information.
BW2 — Output binary image containing only perimeter pixels of objects logical array
Output image containing only perimeter pixels of objects, returned
as a logical array.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
bwperim supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic MATLAB Host Computer
target platform, bwperim generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.
bwperim supports only 2-D images.
bwperim does not support a no-output-argument
syntax.
The connectivity matrix input argument, conn,
must be a constant.
GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
bwperim supports only 2-D images.
bwperim does not support a no-output-argument
syntax.
The connectivity matrix input argument, conn,
must be a constant.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.