Convex Hull Matlab Code And Explanation


Convex Hull:

Consider a set S its convex hull would be a set H such that if we join any two points of set H with a straight line this straight line lies entirely in H. This convex hull H of set S is the smallest convex set that contains S in it. The set obtained by difference of these two sets(H-S) is called the “Convex Deficiency” of set S.

A convex hull describes an object its orientation in an image which can be very useful in image processing. As an object may have different convex hull sets with respect to its different orientations in an image and the areas of sets obtained from these orientations of an object can tell us that in what position or orientation is placed in that image.

Algorithm for Convex Hull:

Step 1. Let Bi, i=1,2,3,4, represent four structuring elements shown in figure below. The origin of all these elements is at centre and ‘x’ represents ‘don’t-care’ conditions. It means that for a match the centre pixel of these elements needs to be at 0 pixel of the region of image the mask is placed on and the shaded pixel of element be masking 1 on the image region behind.  The ‘x’ pixels are don’t care whether they are at 1 or 0. You can see that if we rotate B1 clockwise by 90 degrees it will become B2 and rotate B2 by 90 degrees clockwise will give B3 and so on. We can write Bi=clockwise 90 degrees rotation of Bi-1.









Step 2. The procedure consists of applying hit-or-miss transform to set A(the image) iteratively with element B1 as long as no changes occur, then we perform union with A and store as D1. We then repeat this same procedure with B2 until no changes occur and store it in D2. We do this same step with remaining 2 elements B3 and B4 and store the result in D3 and D4 respectively.

Step 3. We then take union of all these D’s which will give us the convex hull of set A(the image).


The hit-miss transform used in this procedure we don’t use background. If you want to learn about hit-miss transform and its code for Matlab click here.

Matlab Code:



The image ‘impcon.bmp’ needed for proper execution of this code as this image is read in this code.To get it click here


  1. By vinoth


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>