This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Generate convex hull image from binary image


CH = bwconvhull(BW)
CH = bwconvhull(BW,method)
CH = bwconvhull(BW,'objects',conn)



CH = bwconvhull(BW) computes the convex hull of all objects in BW and returns CH, a binary convex hull image.

CH = bwconvhull(BW,method) specifies the desired method for computing the convex hull image.

CH = bwconvhull(BW,'objects',conn) specifies the desired connectivity used when defining individual foreground objects. The conn parameter is only valid when the method is 'objects'.


collapse all

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.

I = imread('coins.png');

BW = I > 100;

CH = bwconvhull(BW);
title('Union Convex Hull');

CH_objects = bwconvhull(BW,'objects');
title('Objects Convex Hull');

Input Arguments

collapse all

Input binary image, specified as a 2-D logical array.

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

Method used to compute the convex hull, specified as one of the following:

'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

Connectivity, specified as either of the following scalar values. The conn parameter is only valid when the method is 'objects'.

4Two-dimensional, four-connected neighborhood
8Two-dimensional, eight-connected neighborhood.

You can also define connectivity in a more general way by using a 3-by-3 matrix of 0s and 1s. The 1-valued elements define neighborhood locations relative to conn's center element. conn must be symmetric about its center element.

Data Types: double

Output Arguments

collapse all

Binary mask of the convex hull of all foreground objects in the input image, returned as a 2-D logical array.

Introduced in R2011a

Was this topic helpful?