Skip to main content

Shape Count Range

This rule checks the number of shapes in the image and ensures it is within the specified range.

Parameter table

paramunitrequireddescription
minShapeCountCountnoMinimum number of shapes (minShapeCount)
maxShapeCountCountnoMaximum number of shapes (maxShapeCount)

Detailed description

The Rule Shape Count Range counts the number of shapes present in an image and verifies that this count is within the specified range.

To detect shapes, the image is first reduced to 8 colors. Then, for each color in the image, a binary version of the image is created where white represents the current color and black represents other colors.

The algorithm presented in the paper ("Topological Structural Analysis of Digitized Binary Images by Border Following" by Satoshi Suzuki and Keiichi Abe)[https://www.sciencedirect.com/science/article/abs/pii/0734189X85900167] is then applied to each binary image to detect contours.

The minimum area of contours to consider is set to 0.2% of the total area of the image, while the maximum area of contours to consider is 60% of the total area of the image.

(sofa)[https://img.playmakers.co/barista/docs/sofa.png] One can see 22 highlighted shapes on the sofa.

(shapes)[https://img.playmakers.co/barista/docs/highlighted-shapes.png] One can see the 9 very clear and separate shapes on this image that have been highlighted.

How to setup

This rule evaluates the number of shapes in the image and ensures it is within the specified range. Key parameters include:

  • minShapeCount: Minimum number of shapes.
  • maxShapeCount: Maximum number of shapes.

At least one of these parameters is required.

Examples

valuevalidmaxShapeCountminShapeCountdescription
shapes63The number of shapes in the image should be between 3 and 6.
sofa5The number of shapes in the image should be greater than or equal to 5.