bwmorph
Morphological operations on binary images
Description
Examples
Perform Morphological Operations on Binary Image
Read binary image and display it.
BW = imread('circles.png');
imshow(BW);
Remove interior pixels to leave an outline of the shapes.
BW2 = bwmorph(BW,'remove');
figure
imshow(BW2)
Get the image skeleton.
BW3 = bwmorph(BW,'skel',Inf);
figure
imshow(BW3)
Input Arguments
BW
— Binary image
2-D numeric matrix | 2-D logical matrix
Binary image, specified as a 2-D numeric matrix or 2-D logical matrix. For numeric input,
any nonzero pixels are considered to be 1
(true
).
operation
— Morphological operation to perform
character vector | string scalar
Morphological operation to perform, specified as one of the following.
Operation | Description |
---|---|
| Perform the morphological bottom hat operation, returning the image minus the morphological closing of the image. The
|
| Find branch points of skeleton. For example: 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 1 becomes 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 Note: To find
branch points, the image must be skeletonized. To create a skeletonized image,
use |
| Bridge unconnected pixels, that is, sets 1 0 0 1 1 0 1 0 1 becomes 1 1 1 0 0 1 0 1 1 |
| Remove isolated pixels (individual 0 0 0 0 1 0 0 0 0 |
| Perform morphological closing (dilation followed by erosion). The
|
| Use diagonal fill to eliminate 8-connectivity of the background. For example: 0 1 0 0 1 0 1 0 0 becomes 1 1 0 0 0 0 0 0 0 |
| Find end points of skeleton. For example: 1 0 0 0 1 0 0 0 0 1 0 0 becomes 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 Note: To find end
points, the image must be skeletonized. To create a skeletonized image, use
|
| Fill isolated interior pixels (individual 1 1 1 1 0 1 1 1 1 |
| Remove H-connected pixels. For example: 1 1 1 1 1 1 0 1 0 becomes 0 0 0 1 1 1 1 1 1 |
| Set a pixel to |
| Perform morphological opening (erosion followed by dilation). The
|
| Remove interior pixels. This option sets a pixel to |
| With |
| With When working
with 3-D volumes, or when you want to prune a skeleton, use the |
| Remove spur pixels. For example: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 becomes 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 0 0 |
| With |
| With |
| Perform the morphological top hat operation, returning the image minus the morphological opening of the image. The
|
Tip
To perform morphological erosion or dilation, use the imerode
or imdilate
function, respectively. If you
want to replicate the dilation or erosion performed by the
bwmorph
function, then specify the neighborhood as
ones(3)
.
Data Types: char
| string
n
— Number of times to perform operation
positive integer | Inf
Number of times to perform the operation, specified as a positive integer or
Inf
. When you specify n
as
Inf
, the bwmorph
function repeats the
operation until the image no longer changes.
Example: 100
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Output Arguments
BW2
— Image after morphological operations
2-D logical matrix
Image after morphological operations, returned as a 2-D logical matrix.
Data Types: logical
Algorithms
When used with the "thin"
option, bwmorph
uses the
following algorithm [3]:
In the first subiteration, delete pixel p if and only if the conditions G1, G2, and G3 are all satisfied.
In the second subiteration, delete pixel p if and only if the conditions G1, G2, and are all satisfied.
Condition G1:
where
x1, x2, ..., x8 are the values of the eight neighbors of p, starting with the east neighbor and numbered in counter-clockwise order.
Condition G2:
where
Condition G3:
Condition G3':
The two subiterations together make up one iteration of the
thinning algorithm. When the user specifies an infinite number of
iterations (n=Inf
), the iterations are repeated
until the image stops changing. The conditions are all tested using applylut
with
precomputed lookup tables.
References
[1] Haralick, Robert M., and Linda G. Shapiro, Computer and Robot Vision, Vol. 1, Addison-Wesley, 1992.
[2] Kong, T. Yung and Azriel Rosenfeld, Topological Algorithms for Digital Image Processing, Elsevier Science, Inc., 1996.
[3] Lam, L., Seong-Whan Lee, and Ching Y. Suen, "Thinning Methodologies-A Comprehensive Survey," IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, September 1992, page 879, bottom of first column through top of second column.
[4] Pratt, William K., Digital Image Processing, John Wiley & Sons, Inc., 1991.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
bwmorph
supports the generation of C code (requires MATLAB® Coder™). Note that if you choose the genericMATLAB Host Computer
target platform,bwmorph
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.When generating code, the character vectors or string scalars specifying the operation must be a compile-time constant and, for best results, the input image must be of class
logical
.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
When generating code, the character vectors or string scalars specifying the operation must be a compile-time constant and, for best results, the input image must be of class
logical
.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.
Version History
Introduced before R2006a
See Also
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)