bwconvhull

Generate convex hull image from binary image

Syntax

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

Description

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'.

Input Arguments

BW

A logical 2-D image

method

A string that can have the following values:

  • '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.

Default: 'union'

conn

Connectivity. Can have the following scalar values:

  • 4: Two-dimensional, four-connected neighborhood.

  • 8: Two-dimensional, eight-connected neighborhood.

Additionally, conn may be defined in a more general way, 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.

Default: 8

Output Arguments

CH

A logical, convex hull image, containing the binary mask of the convex hull of all foreground objects in BW.

Examples

Display the binary convex hull of an image:

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');

Was this topic helpful?