bwperim
Find perimeter of objects in binary image
Description
bwperim(___)
without output arguments displays
the binary image of the perimeter in a new figure window. To use this syntax,
BW
must be a 2-D binary image.
Examples
Find Perimeter of Objects in Binary Image
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')
Find Perimeter Pixels in Binary Image
This example shows how to find the perimeter pixels in a binary image using the bwperim
function.
Read a binary image into the workspace.
BW1 = imread('circbw.tif');
Find the perimeters of objects in the image.
BW2 = bwperim(BW1);
Display the original image and the image showing perimeters side-by-side.
montage({BW1,BW2},'BackgroundColor','blue','BorderSize',5)
Input Arguments
BW
— Input binary image
numeric array | logical array
Input binary image, specified as a numeric or logical array of any
dimension. For numeric input,
any nonzero pixels are considered to be 1
(true
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
conn
— Pixel connectivity
4
| 8
| 6
| 18
| 26
| 3-by-3-by- ... -by-3 matrix of 0
s and
1
s
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 | ||
| 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. |
Current pixel is shown in gray. |
| 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. |
Current pixel is shown in gray. |
Three-Dimensional Connectivities | ||
| 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:
|
Current pixel is center of cube. |
| 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:
|
Current pixel is center of cube. |
| 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:
|
Current pixel is center of cube. |
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
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. See Specifying Custom Connectivities for more information.
Data Types: double
| logical
Output Arguments
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.
Data Types: logical
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 genericMATLAB 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 Types of Code Generation Support in Image Processing Toolbox.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.
Version History
Introduced before R2006a
See Also
bwarea
| imfill
| conndef
| bweuler
| bwboundaries
| bwtraceboundary
| bwferet
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)