bwconvhull
Generate convex hull image from binary image
Description
Examples
Display Binary Convex Hull of Image
Read a grayscale image into the workspace. Convert it into a binary image and calculate the union binary convex hull. Finally, calculate the objects convex hull and display all the images in one figure window.
subplot(2,2,1); I = imread('coins.png'); imshow(I); title('Original'); subplot(2,2,2); BW = I > 100; imshow(BW); title('Binary'); subplot(2,2,3); CH = bwconvhull(BW); imshow(CH); title('Union Convex Hull'); subplot(2,2,4); CH_objects = bwconvhull(BW,'objects'); imshow(CH_objects); title('Objects Convex Hull');
Input Arguments
BW
— Input binary image
2-D logical matrix
Input binary image, specified as a 2-D logical matrix.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
method
— Method used to compute the convex hull
'union'
(default) | 'objects'
Method used to compute the convex hull, specified as one of the following:
Value | Description |
---|---|
'union' | Compute the convex hull of all foreground objects, treating them as a single object |
'objects' | Compute the convex hull of each connected component of BW individually. CH contains
the convex hulls of each connected component. |
Data Types: char
| string
conn
— Pixel connectivity
8
(default) | 4
| 3-by-3 matrix of 0
s and 1
s
Pixel connectivity, specified as one of these values The
conn
parameter is only valid when the
method
is 'objects'
.
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. |
Connectivity can also be defined in a more general way by specifying a
3-by-3 matrix of 0
s and 1
s. The
1
-valued elements define neighborhood locations
relative to the center element of conn
. The matrix must
be symmetric about its center element.
Data Types: double
Output Arguments
CH
— Binary mask of the convex hull of all foreground objects in the input image
2-D logical matrix
Binary mask of the convex hull of all foreground objects in the input image, returned as a 2-D logical matrix.
Version History
Introduced in R2011a
See Also
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)