Blob separating for counting and sizing particles
In defect detection or life science applications counting and sizing particles is a quite common requirement. What may seem easy at first glance can become challenging if particles stick together. In the following we illustrate two possible solutions.
1. Region Morphology
After extracting the particle region with a threshold operator, we erode the region just enough to separate the particles, but not so much that we erase them completely. Once disconnected we simply “inflate” them back to the original size. In HALCON this is done with the following code sequence:
binary_threshold(Image, Region, ‘max_separability’, ‘light’, _)
erosion_circle(Region, RegionErosion, 13.5)
dilation_circle(ConnectedRegions, RegionDilation, 13.5)
2. Distance Transform with Watersheding
The Distance Transform gives you the distance of each region pixel from the region boundary and represents the result as an image. The resulting image is bright in the center of the regions and gets darker towards their boundary. Invert that image, and the regions form “lakes” with the deepest spot being in the center. Now all you have to do is separate the “lakes” from each other, and the perfect technique for that is called watersheding
In HALCON this translates into the following code:
get_image_size(Image, Width, Height)
distance_transform(Region, DistanceImage, ‘euclidean’, ‘true’, Width, Height)
convert_image_type(DistanceImage, ImageConverted, ‘uint2’)
watersheds_threshold(ImageInvert, Basins, 2)
intersection(Basins, Region, RegionIntersection)
You can copy and paste the code above into HDevelop, and it will run.