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. In Workspace Explorer open workspace Examples and in Film strip window select Waffles dataset. Drag the Image channel to the ACQUIRE section.
  2. To threshold an image, use the ThresholdToRegion. Set the inMaxValue to 200.
  3. Add the ErodeRegion filter and set the inRadiusX to 20. Connect the outRegion from a previous filter with inRegion of the current one.
  4. To bound the region, use the RegionBoundingRectangle_OrNil filter.
  5. To create a rectangle region, use the CreateRectangleRegion and set the inFrameWidth to 656 and the 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 the ThresholdToRegion again, set the inMaxValue to 120, connect the inImage with the ReadFilmstrip output and connect the inRoi with the outRegion from the CreateRectangleRegion filter.
  7. To determine the area of chocolate within reduced region, right-click on the outRegion output, find Property Outputs and choose Area. This selected output should appear in the filter as the outRegion.Area.
  8. To check if the region corresponding to the chocolate has the area in specified range, use the TestIntegerInRange filter and connect the outRegion.Area with the inValue input of the current filter. Set the inMaximum to 600.
  9. Now create a formula with two outputs:

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

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

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

      ResultColorID = if inRegionArea<=600 then 1 else 0

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

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

Macrofilter Main

Used Filters

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

Further Readings

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