Functions > Image Processing > Feature Extraction > Example: Convex Hull
  
Example: Convex Hull
Use the cnvxhull function to find the convex hull of the pixels with a foreground intensity value fg in matrix M. The output is binarized with values of 1 inside the convex hull and 0 outside. The algorithm used is described in Digital Picture Processing by A. Rosenfeld and A. C. Kak, page 269, 1982.
The hull is found by choosing P1 as the leftmost and topmost point of the set of pixels in M and L1 as the horizontal line through P1. Then it rotates L1 about P1 until it hits the value fg in the set of pixels. Calling the resulting rotated line L2 and letting P2 be the point farthest from P1 along L2, the algorithm then repeats, until Pn = P1. The union of {P1,P2, ... , Pn-1} are the vertices of the convex hull.
For information on using this example, refer to About Image Processing Examples.
1. Define an input matrix.
Click to copy this expression
2. Compute the convex hull of the set with foreground pixel value 1.
Click to copy this expression
Click to copy this expression
The convex hull contains all the pixels of 1 in the original matrix, and it is the smallest convex set.
3. Select the foreground pixel value as 2, and recalculate the convex hull.
Click to copy this expression
Click to copy this expression
4. Superimpose a binary image of a kernel of corn with its convex hull to demonstrate the usefulness of the hull in describing the contour and holes in an image.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
5. Find the convex hull of the white (1) pixels in the binarized image, and then subtract the image from the hull to find the convex deficiency. Instead of subtracting directly, the binarized image and convex hull are scaled so the area outside the hull is gray, the image pixels black, and the convex deficiency white.
Click to copy this expression
Click to copy this expression
Click to copy this expression
6. Show the M, Mbin255 and Mdef images side by side.
(corn1.bmp)
(mbin_255.bmp)
(mdef.bmp)
The outside of the hull is gray in M, the image is black Mbin55, and the convex deficiency appears in white in the final image, Mdef.