You are here: Start » Tutorial Exercises » Count the Mounts (count_mounts)

Count the Mounts (count_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

Return an Integer value with the count of objects depicted on an input image.

Hints

To solve this problem the Blob Analysis technique should 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 represents black pixels. Red and orange colors represents white pixels in the image. As it is seen, the background color is almost uniform (except for compression artifacts). To extract an object from the background ThresholdToRegion filter can be used.

Next, the found region should be split into separate objects. For this purpose SplitRegionIntoBlobs filter should be used. Then, a number of objects can be found directly from the filter's output outBlobs.

To get the count of the found elements output outBlobs should be expanded as in the image below.

Solution (AVS)

  1. Add LoadImage filter to get an image from the input directory.
  2. To extract objects from the image use ThresholdToRegion filter with the value of inMaxValue set to 128 and inMinBlobArea set to Auto.
  3. To split a single region to multiple objects use SplitRegionIntoBlobs filter.
  4. To get the number of blobs right-click on SplitRegionIntoBlobs port and expand Count value.
  5. Show outBlobs.Count in a preview window.

Main Macrofilter uses a basic Blob Analysis technique to get a count of objects.