Skip to content
Douglas Blank edited this page Oct 24, 2022 · 8 revisions

Image

class Image(Asset)

An Image asset.

__init__

def __init__(data=None,
             name=None,
             format="png",
             scale=1.0,
             shape=None,
             colormap=None,
             minmax=None,
             channels="last",
             metadata=None,
             source=None,
             unserialize=False)

Logs the image.

Arguments:

  • data - Required if source not given. data is one of the following:
    • a path (string) to an image
    • a file-like object containing an image
    • a numpy matrix
    • a TensorFlow tensor
    • a PyTorch tensor
    • a list or tuple of values
    • a PIL Image
  • name - String - Optional. A custom name to be displayed on the dashboard. If not provided the filename from the data argument will be used if it is a path.
  • format - Optional. String. Default: 'png'. If the data is actually something that can be turned into an image, this is the format used. Typical values include 'png' and 'jpg'.
  • scale - Optional. Float. Default: 1.0. If the data is actually something that can be turned into an image, this will be the new scale of the image.
  • shape - Optional. Tuple. Default: None. If the data is actually something that can be turned into an image, this is the new shape of the array. Dimensions are (width, height) or (width, height, colors) where colors is 3 (RGB) or 1 (grayscale).
  • colormap - Optional. String. If the data is actually something that can be turned into an image, this is the colormap used to colorize the matrix.
  • minmax - Optional. (Number, Number). If the data is actually something that can be turned into an image, this is the (min, max) used to scale the values. Otherwise, the image is autoscaled between (array.min, array.max).
  • channels - Optional. Default 'last'. If the data is actually something that can be turned into an image, this is the setting that indicates where the color information is in the format of the 2D data. 'last' indicates that the data is in (rows, columns, channels) where 'first' indicates (channels, rows, columns).

to_pil

def to_pil()

Return the image as a Python Image Library (PIL) image.

Example:

>>> import kangas as kg
>>> image = kg.Image("filename.jpg").to_pil()
>>> image.show()

show

def show()

Show the image.

convert_to_source

def convert_to_source(filename=None)

A PNG filename to save the loaded image.

Under development.

add_regions

def add_regions(label, *regions, score=None)

Add polygon regions to an image.

Arguments:

  • label - (str) the label for the regions
  • regions - list or tuples of at least 3 points
  • score - (optional, number) a score associated with the region.

Example:

>>> image = Image()
>>> image.add_regions("car", [(x1, y1), ...], [(x2, y2), ...])

add_bounding_boxes

def add_bounding_boxes(label, *boxes, score=None)

Add bounding boxes to an image.

Arguments:

  • label - (str) the label for the regions
  • boxes - list or tuples of exactly 2 points (top-left, bottom-right)
  • score - (optional, number) a score associated with the region.

Example:

>>> image = Image()
>>> box1 = [(x1, y1), (x2, y2)]
>>> box2 = [(x1, y1), (x2, y2)]
>>> image.add_bounding_boxes("Person", box1, box2, ...)

add_mask

def add_mask(label, image)

Add a mask to an image.

Under development.

Example:

>>> image = Image()
>>> image.add_mask("attention", Image(MASK))

add_annotations

def add_annotations(text, anchor, *points, score=None)

Add an annotation to an image.

Under development.

Example:

>>> image = Image()
>>> image.add_annotations("Tumors", (50, 50), (100, 100), (200, 200), ...)

Table of Contents

Clone this wiki locally