Plums-Microlib Painter

The actual painter composition is exposed here.

class plums.plot.engine.painter.Position[source]

Bases: object

Simple enum to represent the position of the confidence label.

LEFT = 'left'
RIGHT = 'right'
class plums.plot.engine.painter.Geometry(record, zoom=1)[source]

Bases: object

A class that represents a record geometry and computes meaningful properties.

Parameters
  • record (tuple, list) – The record to extract coordinates from.

  • zoom (int) – Optional. Defaults to 1. Zoom level to use.

Raises
  • TypeError – When coordinates is not a collection or a nested.

  • ValueError – When the record is invalid.

  • ValueError – When a point has not 2 coordinates

  • ValueError – When coordinates collection is empty.

  • ValueError – When first and last coordinates differ.

  • ValueError – When the record has an invalid geometry type (should be either Polygon or Point).

property min_x

The minimum value of the coordinates along X axis.

Type

int

property max_x

The maximum value of the coordinates along X axis.

Type

int

property min_y

The minimum value of the coordinates along Y axis.

Type

int

property max_y

The maximum value of the coordinates along Y axis.

Type

int

property centroid

The centroid of the given geometry (mean along X and Y axes).

Type

tuple

property coordinates

Full list of coordinates, using PIL format (i.e. [(x1, y1), ...]).

Type

list

property leftmost_coordinate

The upper-leftmost coordinates as a (x, y) tuple.

Type

tuple

property rightmost_coordinate

The upper-rightmost coordinates as a (x, y) tuple.

Type

tuple

class plums.plot.engine.painter.Draw(size, zoom, mode, background_color)[source]

Bases: object

A wrapper class arround ImageDraw to customize drawing methods.

Parameters
  • size (tuple) – The tile dimensions as (width, height) tuple.

  • zoom (int) – Zoom level to use.

  • mode (str) – Image mode to use (matching ImageMode) (e.g. RGBA)

  • background_color (tuple) – Color to use for the image background as a tuple (RGB or RGBA)

_draw

An object that can be used to draw in the given image _overlay.

Type

ImageDraw

property overlay

The overlay on top of the tile, including annotation drawings.

Type

Image

circle(centroid, fill_color)[source]

Draw a particular ellipse with a radius depending on the zoom level.

Parameters
  • centroid (tuple) – The centroid coordinates as a (x, y) tuple.

  • fill_color (tuple) – The color to use for the circle. RGB or RGBA format.

line(points, fill_color)[source]

Draw record geometry with successive lines since PIL does not support polygon thickness.

Parameters
  • points (list) – A list of points as (x, y) tuples.

  • fill_color (tuple) – The color to use for the lines. RGB or RGBA format.

polygon(points, fill_color)[source]

Draw a polygon, used for the confidence label.

Parameters
  • points (list`) – A list of point as (x, y) tuples.

  • fill_color (tuple) – The color to use for the polygon. RGB or RGBA format.

text(text_coordinates, text, font, fill_color)[source]

Draw a text string at the given position.

Parameters
  • text_coordinates (tuple) – Top-left corner text coordinates as a (x, y) tuple.

  • text (str) – Text to be drawn.

  • font (ImageFont) – Font familly to be used.

  • fill_color (tuple) – The color to use for the text. RGB or RGBA format.

class plums.plot.engine.painter.TagPainter(descriptor, text_margin=2, text_size=11, zoom=1)[source]

Bases: object

A tag artist class which draw a tag next to a given Record geometry.

Parameters
  • descriptor (Descriptor) –

    The Descriptor description to plot next to each Record.

    Note

    The TagPainter class assumes that each Record have already been described by the provided Descriptor.

  • text_margin (int) – Optional. Default to 2. The margin in pixel to leave between the tag text and its border.

  • text_size (int) – Optional. Default to 11. The tag text font size in pixel.

  • zoom (int) – Optional. Defaults to 1. Zoom level to use.

New in version 0.2.0.

draw(record, draw)[source]

Draw a tag next to the provided Record using the provided Draw.

Parameters
  • record (Record) – A Record on which to attach a tag containing its description.

  • draw (Draw) – A Draw instance on which to draw the tag, preferably the Record draw instance.

class plums.plot.engine.painter.PainterBase(plot_centers=False, plot_tag=None, zoom=1, fill=False, alpha=64, **kwargs)[source]

Bases: abc.ABC

An abstract base class that defines the basic elements a Painter needs to draw a data point.

Parameters
  • plot_centers (bool) – Optional. Defaults to False. Plot records centers (instead of full geometry).

  • plot_tag (Descriptor) –

    Optional. Defaults to None. Besides the geometry, display a Record description in a tag attached to the Record.

    Note

    The PainterBase class assumes that each Record have already been described by the provided Descriptor.

  • zoom (int) – Optional. Defaults to 1. Zoom level to use.

  • fill (bool) – Optional. Default to False. A flag which represents whether to draw filled polygons.

  • alpha (int) – Optional. Defaults to 64. A positive integer (between 0 and 255) that represents the fill transparency.

abstract draw(data_point)[source]

Draw a data point (annotations on a given tile) and return the composed Image.

Parameters

data_point (DataPoint) – Data point to be drawn (tile + annotations).

Raises

ValueError – When a record has an invalid geometry type.

Returns

The composed image (tile with annotations)

Return type

Image

class plums.plot.engine.painter.Painter(plot_centers=False, plot_tag=None, zoom=1, fill=False, alpha=64, **kwargs)[source]

Bases: plums.plot.engine.painter.PainterBase

A basic Painter that implements the PainterBase class.

The role of the painter is to aggregate annotations on a given tile, giving to the user a meaningful representation of the records.

Parameters
  • plot_centers (bool) – Optional. Defaults to False. Plot records centers (instead of full geometry).

  • plot_tag (Descriptor) –

    Defaults to None. Besides the geometry, display a Record description in a tag attached to the Record.

    Note

    The Painter class assumes that each Record have already been described by the provided Descriptor.

  • zoom (int) – Optional. Defaults to 1. Zoom level to use.

  • fill (bool) – Optional. Default to False. A flag which represents whether to draw filled polygons.

  • alpha (int) – Optional. Defaults to 64. A positive integer (between 0 and 255) that represents the fill transparency.

MODE = 'RGBA'
TEXT_MARGIN = 2
TITLE_HEIGHT = 30
TITLE_SIZE = 15
TITLE_BACKGROUND_COLOR = (46, 49, 49)
TAG_TEXT_SIZE = 11
draw(data_point)[source]

Draw a data point (annotations on a given tile) and return the composed Image.

Parameters

data_point (DataPoint) – Data point to be drawn (tile + annotations).

Raises

ValueError – When a record has an invalid geometry type.

Returns

The composed image (tile with annotations)

Return type

Image