A convex hull of a set of points is defined as the smallest convex polygon containing all the points. In other words, it is the outer boundary of the set of points that forms a shape with no indentations or concave portions.
The convex hull can be represented as a polygon formed by connecting the outermost points counterclockwise or clockwise. It can also be described as the intersection of all convex sets containing the given points.
The following slides illustrate the points and their convex hull.
The convex hull has various applications, such as:
Computational geometry: It is used in algorithms for solving problems like finding the closest pair of points or solving linear programming problems.
Image processing: Convex hulls can be used to analyze and recognize image shapes, particularly for object recognition or tracking.
Robotics: Convex hulls are useful for collision detection and path planning in robotics applications.
Game development: Convex hulls are employed in physics engines for collision detection and response between objects in games.
In image processing, the convex hull is used as a technique to analyze and extract shape information from images. It helps identify and represent the outer boundaries of objects or regions within an image.
Here’s how the convex hull is applied in image processing:
Object segmentation: The convex hull can be utilized to segment objects from the background in an image. By identifying the outermost points of an object and constructing its convex hull, it is possible to separate the object from the surrounding area.
Shape analysis: The convex hull can provide valuable information about the shape and geometry of an object within an image. Encapsulating its outer boundary helps determine an object’s overall size, orientation, and extent.
Object recognition: Convex hulls can be employed as features for object recognition and classification. By extracting the convex hull of an object and comparing it with predefined templates or models, it becomes possible to identify and classify objects in an image.
Contour approximation: The convex hull can be used to approximate the contour of an object or region. By connecting the outermost points of the object’s contour, a simplified representation of the shape can be obtained, which is useful for further analysis or processing.
Let’s understand the working example of the convex hull in image processing below.
import matplotlib.pyplot as pltfrom skimage.morphology import convex_hull_imagefrom skimage import data, img_as_floatfrom skimage.util import invertfrom skimage.filters import threshold_otsuimport skimage.io as skioimage = skio.imread("points.png", as_gray=True)thresh = threshold_otsu(image)image = image > threshchull = convex_hull_image(invert(image))fig, axes = plt.subplots(1, 2, figsize=(12, 6))ax = axes.ravel()ax[0].set_title('Points')ax[0].imshow(image, cmap=plt.cm.gray)ax[0].set_axis_off()ax[1].set_title('Convex Hull')ax[1].imshow(chull, cmap=plt.cm.gray)ax[1].set_axis_off()plt.tight_layout()plt.show()
pyplot
module from the matplotlib
library. This module provides an interface for creating plots and visualizations.convex_hull_image
function from the skimage.morphology
module. This function calculates the convex hull of a binary image.data
and img_as_float
modules from the skimage
library. These modules provide utility functions for working with images.invert
function from the skimage.util
module. This function inverts the pixel values of an image.threshold_otsu
function from the skimage.filters
module. This function calculates the optimal threshold value for image segmentation using Otsu’s method.skio
module from the skimage.io
library. This module provides functions for reading and writing images.skio.imread
function. The resulting image is stored in the image
variable.thresh
variable.image
variable.convex_hull_image
function and store the result in the chull
variable.The following lines involve plotting and visualization:
subplots
function from pyplot
. The subplots will be arranged in a 1x2 grid, and the figure size is set to (12, 6) inches. The resulting figure and axes are stored in the fig
and axes
variables.axes
variable and store them in the ax
variable.set_title
function of the first axis (ax[0]
).imshow
function of the first axis. The colormap plt.cm.gray
is used to display the image in grayscale.set_axis_off
function of the first axis.set_title
function of the second axis (ax[1]
).imshow
function of the second axis. The colormap plt.cm.gray
is used to display the image in grayscale.set_axis_off
function of the second axis.tight_layout
function.show
function from pyplot
.Free Resources