Blobs.filter#

Blobs.filter(area: Any = None, circularity: Any = None, color: bool | None = None, touch: bool | None = None, aspect: Any = None) Blobs[source]#

Filter blobs

Parameters:
  • area (scalar or array_like(2), optional) – area minimum or range, defaults to None

  • circularity (scalar or array_like(2), optional) – circularity minimum or range, defaults to None

  • color (bool, optional) – color/polarity to accept, defaults to None

  • touch (bool, optional) – blob touch status to accept, defaults to None

  • aspect (scalar or array_like(2), optional) – aspect ratio minimum or range, defaults to None

Returns:

set of filtered blobs

Return type:

Blobs

Return a set of blobs that match the filter criteria.

Parameter

Description

"area"

Blob area

"circularity"

Blob circularity

"aspect"

Aspect ratio of equivalent ellipse

"touch"

Blob edge touch status

The filter parameter arguments are:

  • a scalar, representing the minimum acceptable value

  • a array_like(2), representing minimum and maximum acceptable value

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('sharks.png')
>>> blobs = img.blobs()
>>> blobs
Blobs(nblobs=4)
>>> blobs.filter(area=10_000)
Blobs(nblobs=2)
>>> blobs.filter(area=10_000, circularity=0.3)
Blobs(nblobs=1)

Warning

Filtering can destroy the hierarchy of the blobs, deleting parents and children in the blob tree. A blob may have references to parents and children that are not in the filtered set.

References:
Seealso:

sort