You are here: Start » Tutorial Exercises » Count Nails (nails)

Count Nails (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

An Integer value with 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 basic ThresholdToRegion filter.

Objects are physically separated and what gives a great opportunity to split them into separate blobs using SplitRegionIntoBlobs filter.

Regions can be classified using ready-to-use tool ClassifyRegions which can be found in Toolbox in Region Logic group.

Adaptive Vision Studio provides also separate filters that can be used to classify blobs which can be found in Toolbox in Region Feature group.

These filter can be very useful to preform classification using different regions' features.

Solution (AVS)

  1. Add LoadImage filter to the project and select the input image path. It is also possible to drag an image file from outside of Adaptive Vision Studio window.

  2. To separate objects from image background add ThresholdToRegion filter and set its inMaxValue to 200. Uncheck optional value in input inMinValue to set it to its default value.

  3. To separate each object use SplitRegionIntoBlobs. Result of this operation is presented in the picture below. Each blob is presented with a different color.

  4. Experiment with different region features by adding multiple filters from the Region Features category.

  5. Three different region features are presented in the picture below: RegionCircularity, RegionArea and RegionDiameter.

    To show array indexes turn this option on in the image menu.

    In this case most useful feature is provided by filter RegionDiameter and this value is used in further nails classification.

  6. Add filter ClassifyRegions to project and select DiameterLength option on an inFeature input.

  7. Expand outAccepted output and show Count value in a new preview window.

Macrofilter Main counts nails among the other objects.