You are here: Start » Tutorial Exercises » Count Nails
Count Nails
Aim:
Devise an algorithm that counts the nails present among various objects in an image.
Input:
A single image with different objects present.
The input image is stored in the nails directory.
Output:
The number of found nails.
Expected value: 5
Hints:
The backlight source makes objects very contrastive. Objects can be separated from the background very easily using the basic ThresholdToRegion filter.
Objects are physically separated and that makes it possible to split them into separate blobs using the SplitRegionIntoBlobs filter.
Regions can be classified using the ready-to-use ClassifyRegions tool which can be found in the Toolbox -> Region Analysis -> Region Logic group.
FabImage Studio also provides separate filters that can be used to classify blobs which can be found in the Toolbox -> Region Analysis -> Region Logic group.
These filters can be very useful to preform the classification using different regions' features.
Labeling connections is explained in this article.
Solution (FIS):
-
Add the LoadImage filter to the project and select the input image path. It is also possible to drag an image file from outside the FabImage Studio window.
-
To extract the objects from the image background add the ThresholdToRegion filter and set its inMaxValue to 200. Uncheck the optional value in the inMinValue input to set it to its default value.
-
To separate each object use the SplitRegionIntoBlobs. The result of this operation is presented in the picture below. Each blob is displayed with a different color:
-
Experiment with different region features by adding multiple filters from the Region Features category.
-
Three different region features are presented in the picture below: RegionCircularity, RegionArea and RegionDiameter:
To show array indexes turn this option on in the top toolbar:
In this case the most useful feature is provided by the RegionDiameter filter and this value is used in further nails classification.
-
Add the ClassifyRegions filter to the project, select DiameterLength option at the inFeature input and choose appropriate values of the inMinimum and the inMaximum parameters.
-
Expand the outAccepted output and show Count value in a new preview window.
Macrofilter Main counts nails among the other objects.
Further Readings
- Blob Analysis - Article presents detailed information about the Blob Analysis technique.