The following illustrates the source image before and after binarization and noise removal operations:
The example below binarizes an image, determines the center of gravity for each blob, and counts the number of bolts, nuts and washers. Note, the binarizing step produces a considerable number of spurious blobs and holes, so some processing is performed to clean up the blob identifier image before doing any calculations.