Blobs.plot_labelbox#

Blobs.plot_labelbox(fmt: str | None = None, label: str = '{:d}', *, position: str = 'topleft', textcolor: Any = None, labelcolor: Any = None, text_style: dict[str, Any] | None = None, **kwargs: Any) → None[source][source]#

Plot a labelled bounding box of blobs using Matplotlib

Parameters:
  • fmt – Matplotlib format string for the box, such as "r--"

  • label (str or bool, optional) – label to be displayed on the bounding box, defaults to blob id

  • position – place to draw the label: "topleft" (default), "topright", "bottomleft" or "bottomright"

  • textcolor – color of the label text, defaults to black

  • labelcolor – label background color, defaults to the edge color of the box

  • text_style – Matplotlib text options for the label, such as dict(fontsize=12, fontweight="bold"), defaults to None

  • kwargs – Matplotlib patch options for the box, passed to plot_labelbox

The label text color and background can be set by text_style, by textcolor and labelcolor, or by default, and the most specific wins: see plot_labelbox.

Changed in version 2.5.0: Added text_style, and the label background follows the edge color of the box however that was set.

Plot a labelled bounding box for every blob described by this object.

By default the label is the blob id, but a custom label can be provided by setting label to a string with a single format field, e.g. "Blob {:d}". Setting label to True is the same as the default.

By default, blobs are labeled by their blob id.

Examples

>>> from machinevisiontoolbox import Image
>>> im = Image.Read("sharks.png")
>>> blobs = im.blobs()
>>> blobs[:3].plot_labelbox(color="yellow")
>>> blobs[3].plot_labelbox(color="lightblue", linewidth=2, label="3")

(Source code, png, hires.png, pdf)

../../_images/machinevisiontoolbox-Blobs-plot_labelbox-1.png