Computing the convex hull

The convex hull is defined by the smallest convex polygon that surrounds all foreground (white pixels) in the input image. The following code block demonstrates how to compute the convex hull for a binary image:

from skimage.morphology import convex_hull_imageim = rgb2gray(imread('../images/horse-dog.jpg'))threshold = 0.5im[im < threshold] = 0 # convert to binary imageim[im >= threshold] = 1chull = convex_hull_image(im)plot_images_horizontally(im, chull, 'convex hull', sz=(18,9))

The following screenshot shows the output:

The following code block plots the difference image of the original binary image and the computed ...

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.