Skip to content

Annotation

Annotation class

An Annotation object stores annotation which is corresponding to some image. It includes annotation objects (figures), image size, description and tags.

class Annotation:
    def __init__(self, internal_data):

Create Annotation object. Does not copy data.

  • internal_data — annotation data.

Properties

image_size_wh

Image size in pixels as tuple (width, height).

Methods

__getitem__(self, item) and __setitem__(self, key, value)

Access to internal fields like objects (list of objects), tags (list of image tags), description.

update_image_size(self, new_img_np)

Set new image size which is determined from numpy array shape.

  • new_img_np — numpy array to read shape from.

apply_to_figures(self, fn)

Apply function to objects (figures).

  • fn — callback function. Should get single object and return iterable of objects as a result.

normalize_figures(self)

Normalize objects (figures).

pack(self)

Return packed annotation (to write or to send it). Packed annotation is a dictionary ready for JSON-izing. The i/o format is described here.

add_object_back(self, obj)

Add new object (figure) to annotation under existing figures.

  • obj — object (figure).

add_object_front(self, obj)

Add new object (figure) to annotation above existing figures.

  • obj — object (figure).

@classmethod from_packed(cls, packed_ann, project_meta)

Read annotation from i/o format. Returns new Annotation object.

  • packed_ann — packed annotation (a dictionary read from JSON). The i/o format is described here.
  • project_metaProjectMeta object with corresponding project meta.

@classmethod new_with_objects(cls, imsize_wh, objects)

Create annotation from objects. Returns new Annotation object.

  • imsize_wh — image size in pixels as tuple (width, height).
  • objects — iterable of objects (figures).