You are here: Start » Tutorial Exercises » Bottle Inspector Part 2: Measuring Liquid Level (bottles_2_level)

Bottle Inspector Part 2: Measuring Liquid Level (bottles_2_level)

Aim

Extend the "Bottle Inspector Part 1" program with measurement of the liquid level for each bottle.

Input

  • A set of images of bottles.
  • An array containing one coordinate systems for each bottle.

Images are stored in bottles directory.

Output

Create a new CheckLiquidLevel macrofilter that returns for each single bottle:

  • A point that represents the liquid level (as Point2D),
  • A boolean value that shows if the liquid level is correct (as Bool).

Hints

Start by creating a coordinate system for each bottle, so that we can define liquid level measurement as a local operation that will be repeated in multiple coordinate systems. Use a CreateCoordinateSystemFromPoint filter with its input connected to the outStripes.Point1 output.

The pixel intensity profile along a line segment (oriented from top to down) crossing the liquid level looks like this:

As we can see in the profile, there is a peak that represents a bright border between the liquid and the empty part of a bottle. Note that this might be counter-intuitive, but the liquid is actually not much brighter than the empty space above it. This peak in the profile starts with a dark-to-bright transition, or a raising edge. To find this edge we use a ScanSingleEdge filter.

Solution (AVS)

Start with the program created in the "Bottle Inspector Part 1" tutorial.

  1. Expose the Point1 property of the outStripes output of the ScanMultipleStripes filter.

  2. Create a coordinate systems from this point using a CreateCoordinateSystemFromPoint filter.

  3. To organize the program, close the three filters added so far, from ScanMultipleStripes to CreateCoordinateSystemFromPoint, in a macrofilter named "DetectBottles". Make sure it has two outputs: outBottleAlignments (CoordinateSystem2DArray) and outCountOK (Bool).

  4. Add a ScanSingleEdge filter with:

    This filter will be executed in the array mode.

  5. Define a scan path:

    • Open the Path editor on the inScanPath input.
    • Create a scan path using a coordinate system from the inScanPathAlignment input. It is shown in the picture below.

  6. Add a formula block with one input named inEdgePoint, connected to the outEdge.Point output of the ScanSingleEdge filter.

  7. Add an outIsOK output (Bool) to this formula with expression "inEdgePoint.Y <= 205 ?? False". The "??" operator specifies what value should be used when the edge point is not detected (Nil).

  8. Extract another macrofilter, "CheckLiquidLevel", which accepts an image and alignment as the inputs, and returns the liquid level point and status (ok/not ok). Accept the suggested transformation when using the "Extract Step..." command to make sure, that the entire macrofilter is executed multiple times - once for each bottle (as opposed to executing it once for the entire array of bottles).

Macrofilter Main performs a bottle inspection.

Macrofilter CheckLiquidLevel finds liquid level from the input image.

Further Readings