colour_checker_detection.detection.filter_clusters#

colour_checker_detection.detection.filter_clusters(clusters: NDArrayInt, swatches: NDArrayInt, swatches_count_minimum: int, swatches_count_maximum: int) NDArrayInt[source]#

Filter clusters by the number of swatches they contain.

Parameters:
  • clusters (NDArrayInt) – The clusters to filter.

  • swatches (NDArrayInt) – The swatches to count within each cluster.

  • swatches_count_minimum (int) – Minimum number of swatches required in a cluster.

  • swatches_count_maximum (int) – Maximum number of swatches allowed in a cluster.

Returns:

The filtered clusters that contain the expected number of swatches.

Return type:

NDArrayInt

Examples

>>> import numpy as np
>>> clusters = np.array(
...     [
...         [[0, 0], [200, 0], [200, 200], [0, 200]],
...         [[300, 300], [400, 300], [400, 400], [300, 400]],
...     ],
...     dtype=np.int32,
... )
>>> swatches = np.array(
...     [
...         [[50, 50], [100, 50], [100, 100], [50, 100]],
...         [[350, 350], [380, 350], [380, 380], [350, 380]],
...     ],
...     dtype=np.int32,
... )
>>> filter_clusters(clusters, swatches, 1, 2)
array([[[  0,   0],
        [200,   0],
        [200, 200],
        [  0, 200]],

       [[300, 300],
        [400, 300],
        [400, 400],
        [300, 400]]], dtype=int32)