You are here: Start » Tutorial Exercises » Sorting Blobs (sorting)

Sorting Blobs (sorting)

Aim

Create an application that extracts blobs and sorts them by ascending area. Also find the smallest and the biggest blob.

Input

An image that contains several objects with different shapes and sizes.

Images are stored in the sorting directory.

Output

  1. An array of all blobs sorted by ascending area.
  2. The smallest blob.
  3. The biggest blob.

Hints

In the first step, blobs must be extracted from the image. In this case ThresholdToRegion filter can be used.

For the main part of the solution consider the following filters: SortRegions, GetMinimumRegion, GetMaximumRegion.

Solution (AVS)

  1. Load an image using LoadImage filter.

  2. Add ThresholdToRegion filter to extract objects from an input image. Set inMaxValue to 250.0 and set inMinValue to Auto.

  3. Split the extracted region into separate objects using SplitRegionIntoBlobs filter. To remove all graphical noises set the value of inMinBlobArea to 500. This option removes all smaller elements like dust, scraps, etc.

  4. Add filter GetMaximumRegion to find the largest blob. By default elements are sorted by their area. Check other region's features available in inFeature.

  5. Add filter GetMinimumRegion to find the smallest blob.

  6. Add filter SortRegions to sort RegionArray by area.

  7. Use three separate data preview windows to visualize the results.

  8. Use the "Display indices" option on the data preview window with the results of the SortRegions array to see the order of the elements.

Macrofilter Main performs sorting and selection operations on the array of regions.