Other useful features during classification are those that give you information about the blob shape. Two blobs can have similar sizes but different shapes because of a different number of holes, curves, or edges.
For example, in the illustration above, the blobs have similar sizes, but can be distinguished by the shape of their holes. If you treat the holes as the actual blobs (set non-zero pixels as foreground pixels and zero pixels as background pixels), you can extract the differences in shape of the holes.
Two features that can qualify the shape of these holes are:
Compactness (M_COMPACTNESS).
Roughness (M_ROUGHNESS).
The compactness is a measure of how close all particles in the blob are from one another. It is derived from the perimeter and area. A circular blob is most compact and is defined to have a theoretical compactness measure of 1.0 (the minimum); more convoluted shapes have larger values. In practice, due to square pixel discretization, the minimum obtainable compactness is slightly above 1.0.
The roughness is a measure of the unevenness or irregularity of a blob's surface. It is a ratio of the perimeter to the convex perimeter of a blob. Smooth convex blobs have a roughness of 1.0, whereas rough blobs have a higher value because their true perimeter is bigger than their convex perimeter.
Although either of these features can be used in the classification process, compactness is faster to calculate since it is derived using only the area and perimeter.
For a program that, among other things, distinguishes between nuts, bolts and washers by analyzing the compactness of their holes, see the Blob analysis example section later in this chapter.
In some cases, you can also distinguish between blobs by determining the number of holes that they have (M_NUMBER_OF_HOLES). For example, you could distinguish between bolts and nuts in the BoltsNutsWashers.mim image by counting blob holes. However, this is not a very robust measure since a single noise pixel in a bolt blob would count as a hole.