You are here: Start » Tutorial Exercises » Count the Mounts
Count the Mounts
Aim:
Devise an application that counts the mounts in the provided picture.
Input:
A single image with multiple mounts in it.
The input image is stored in the count_the_mounts directory.
Output:
An Integer value with the count of objects depicted in the input image.
Hints:
To solve this issue the Blob Analysis technique could be used. The mounts are much darker than the background so a basic image thresholding can be performed.
The image below shows the difference in the background and objects colors. Blue and violet colors represent black pixels. Red and orange colors represent white pixels in the image.
As you can see, the background color is almost uniform (except for compression artifacts). To extract an object from the background the ThresholdToRegion filter can be used.
Next, the found region should be split into separate objects. For this purpose the SplitRegionIntoBlobs filter needs to be used. Then, a number of objects can be acquired directly from the outBlobs output.
To get the count of the found elements the outBlobs.Count output should be expanded as in the image below.
Labeling connections is explained in this article.
Solution (FIS):
- Add the LoadImage filter to the ACQUIRE section to get an image from the input directory.
- To extract objects from the image add the ThresholdToRegion filter to the PROCESS section and set the value of the inMaxValue to 128 and the inMinBlobArea set to Auto.
- To split the region into multiple objects use the SplitRegionIntoBlobs filter.
- To get the number of blobs, right-click on the outBlobs port and expand the outBlobs.Count value.
- Display the outBlobs.Count in a preview window.
Video Tutorial
Main Macrofilter uses a basic Blob Analysis technique to get a count of objects.
Further Readings
- Blob Analysis - Article presents detailed information about the Blob Analysis technique.