LandmarkGroup

class menpo.landmark.LandmarkGroup(pointcloud, labels_to_masks, copy=True)[source]

Bases: MutableMapping, Copyable, Viewable

An immutable object that holds a PointCloud (or a subclass) and stores labels for each point. These labels are defined via masks on the PointCloud. For this reason, the PointCloud is considered to be immutable.

The labels to masks must be within an OrderedDict so that semantic ordering can be maintained.

Parameters:
  • pointcloud (PointCloud) – The pointcloud representing the landmarks.
  • labels_to_masks (ordereddict {str -> bool ndarray}) – For each label, the mask that specifies the indices in to the pointcloud that belong to the label.
  • copy (bool, optional) – If True, a copy of the PointCloud is stored on the group.
Raises:
  • ValueError – If dict passed instead of OrderedDict
  • ValueError – If no set of label masks is passed.
  • ValueError – If any of the label masks differs in size to the pointcloud.
  • ValueError – If there exists any point in the pointcloud that is not covered by a label.
clear() → None. Remove all items from D.
copy()[source]

Generate an efficient copy of this LandmarkGroup.

Returns:type(self) – A copy of this object
get(k[, d]) → D[k] if k in D, else d. d defaults to None.
has_nan_values()[source]

Tests if the LandmarkGroup contains nan values or not. This is particularly useful for annotations with unknown values or non-visible landmarks that have been mapped to nan values.

Returns:has_nan_values (bool) – If the LandmarkGroup contains nan values.
classmethod init_with_all_label(pointcloud, copy=True)[source]

Static constructor to create a LandmarkGroup with a single default ‘all’ label that covers all points.

Parameters:
  • pointcloud (PointCloud) – The pointcloud representing the landmarks.
  • copy (boolean, optional) – If True, a copy of the PointCloud is stored on the group.
Returns:

lmark_group (LandmarkGroup) – Landmark group wrapping the given pointcloud with a single label called ‘all’ that is True for all points.

items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
keys() → list of D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
tojson()[source]

Convert this LandmarkGroup to a dictionary JSON representation.

Returns:json (dict) – Dictionary conforming to the LJSON v2 specification.
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → list of D's values
view_widget(browser_style='buttons', figure_size=(10, 8), style='coloured')[source]

Visualizes the landmark group object using the visualize_landmarkgroups widget.

Parameters:
  • browser_style ({'buttons', 'slider'}, optional) – It defines whether the selector of the landmark managers will have the form of plus/minus buttons or a slider.
  • figure_size ((int, int), optional) – The initial size of the rendered figure.
  • style ({'coloured', 'minimal'}, optional) – If 'coloured', then the style of the widget will be coloured. If minimal, then the style is simple using black and white colours.
with_labels(labels=None)[source]

A new landmark group that contains only the certain labels

Parameters:labels (str or list of str, optional) – Labels that should be kept in the returned landmark group. If None is passed, and if there is only one label on this group, the label will be substituted automatically.
Returns:landmark_group (LandmarkGroup) – A new landmark group with the same group label but containing only the given label.
without_labels(labels)[source]

A new landmark group that excludes certain labels label.

Parameters:labels (str or list of str) – Labels that should be excluded in the returned landmark group.
Returns:landmark_group (LandmarkGroup) – A new landmark group with the same group label but containing all labels except the given label.
labels

The list of labels that belong to this group.

Type:list of str
lms

The pointcloud representing all the landmarks in the group.

Type:PointCloud
n_dims

The dimensionality of these landmarks.

Type:int
n_labels

Number of labels in the group.

Type:int
n_landmarks

The total number of landmarks in the group.

Type:int