You are here: Start » Program Examples » Waffles

Waffles

Aim

The aim of the program is to separate waffles with a proper amount of chocolate from the damaged ones.

Input

Several images of waffles. The amount of chocolate on the waffles is variable.

Output

Image with its inspection result (OK or not OK) and a rectangle indicating the border between chocolate and waffle area.

Hints

Waffle can be located by thresholding to a region. To check whether a chocolate spilled out of the border area, a region of interest has to be reduced by performing a morphological erosion on the region corresponding to the waffle.

Labeling connections is explained in this article.

Solution (AVS)

  1. Add filter EnumerateImages to program.
  2. To threshold an image, use ThresholdToRegion. Set inMaxValue to 200.
  3. Add filter ErodeRegion and set inRadiusX to 20. Connect outRegion from a previous filter with inRegion of the current one.
  4. To bound the region, use RegionBoundingRectangle_OrNil filter.
  5. To create a rectangle region, use CreateRectangleRegion and set inFrameWidth to 656 and inFrameHeight to 492. Connect the outBoundingRectangle from a previous filter with the inRectangle input.
  6. If you want to threshold the image just in area of the waffle, use ThresholdToRegion again, set inMaxValue to 120, connect inImage with outImage output from the EnumerateImages filter and connect inRoi with outRegion from the CreateRectangleRegion filter.
  7. To determine the area of chocolate within reduced region, right-click on outRegion output, find Property Outputs and choose Area. This selected output should appear in the filter as outRegion.Area.
  8. To check if the region corresponding to the chocolate has the area in specified range, use TestIntegerInRange filter and connect outRegion.Area with inValue input of the current filter. Set inMaximum to 600.
  9. Now create a formula with two outputs:

    • Output ResultStrings of type String? and create there an output message:

      ResultStrings = if inRegionArea<=600 then "OK" else "NOK: Damaged waffle"

    • Output ResultColorID of type Integer? and create there an output message:

      ResultColorID = if inRegionArea<=600 then 1 else 0

  10. Add DrawStrings_MultiColor filter and connect outImage output with inImage input of the current filter.

    • Connect ResultStrings with inStrings input.
    • Connect ResultColorID filter output with the inColorIds of the current filter.
  11. Add DrawRectangles_SingleColor filter and connect outImage from the previous filter with inImage of the current filter. Connect outBoundingRectangle with the inRectangles input of the current filter.
  12. UseoutImage as a preview.

Macrofilter Main

Used Filters

Icon Name Description
DrawStrings_MultiColor Draws strings (text) on an image with multiple colors.
EnumerateImages Emulates image acquisition with images stored on disk.
CreateRectangleRegion Creates a region corresponding to a given rectangle.
RegionBoundingRectangle_OrNil Computes the smallest rectangle containing a region; returns NIL if the region is empty.
ThresholdToRegion Extraction of a region of objects that can be defined by a salient brightness.
ErodeRegion Making the region thinner or removing small parts.
DrawRectangles_SingleColor Draws rectangles on an image with a single color.

Further Readings

  • Blob Analysis - Article presents detailed information about the Blob Analysis technique.