PointCloud

class menpo.shape.pointcloud.PointCloud(points, copy=True)[source]

Bases: Shape

An N-dimensional point cloud. This is internally represented as an ndarray of shape (n_points, n_dims). This class is important for dealing with complex functionality such as viewing and representing metadata such as landmarks.

Currently only 2D and 3D pointclouds are viewable.

Parameters:

points : (n_points, n_dims) ndarray

The array representing the points.

copy : boolean, optional

If False, the points will not be copied on assignment. Note that this will miss out on additional checks. Further note that we still demand that the array is C-contiguous - if it isn’t, a copy will be generated anyway. In general this should only be used if you know what you are doing.

as_vector(**kwargs)

Returns a flattened representation of the object as a single vector.

Returns:

vector : (N,) ndarray

The core representation of the object, flattened into a single vector. Note that this is always a view back on to the original object, but is not writable.

bounds(boundary=0)[source]

The minimum to maximum extent of the PointCloud. An optional boundary argument can be provided to expand the bounds by a constant margin.

Parameters:

boundary : float

A optional padding distance that is added to the bounds. Default is 0, meaning the max/min of tightest possible containing square/cube/hypercube is returned.

Returns:

min_b : (n_dims,) ndarray

The minimum extent of the PointCloud and boundary along each dimension

max_b : (n_dims,) ndarray

The maximum extent of the PointCloud and boundary along each dimension

copy()[source]

An efficient copy of this PointCloud.

Only landmarks and points will be transferred. For a full copy consider using deepcopy().

Returns:

pointcloud : PointCloud

A PointCloud with the same points and landmarks as this one.

distance_to(pointcloud, **kwargs)[source]

Returns a distance matrix between this point cloud and another. By default the Euclidian distance is calculated - see scipy.spatial.distance.cdist for valid kwargs to change the metric and other properties.

Parameters:

pointcloud : PointCloud

The second pointcloud to compute distances between. This must be of the same dimension as this PointCloud.

Returns:

distance_matrix: ``(n_points, n_points)`` `ndarray` :

The symmetric pairwise distance matrix between the two PointClouds s.t. distance_matrix[i, j] is the distance between the i’th point of this PointCloud and the j’th point of the input PointCloud.

from_mask(mask)[source]

A 1D boolean array with the same number of elements as the number of points in the pointcloud. This is then broadcast across the dimensions of the pointcloud and returns a new pointcloud containing only those points that were True in the mask.

Parameters:

mask : (n_points,) ndarray

1D array of booleans

Returns:

pointcloud : PointCloud

A new pointcloud that has been masked.

from_vector(vector)

Build a new instance of the object from it’s vectorized state.

self is used to fill out the missing state required to rebuild a full object from it’s standardized flattened state. This is the default implementation, which is which is a deepcopy of the object followed by a call to from_vector_inplace(). This method can be overridden for a performance benefit if desired.

Parameters:

vector : (n_parameters,) ndarray

Flattened representation of the object.

Returns:

object : type(self)

An new instance of this class.

from_vector_inplace(vector)[source]

Updates this PointCloud in-place with a new vector of parameters

norm(**kwargs)[source]

Returns the norm of this point cloud. This is a translation and rotation invariant measure of the point cloud’s intrinsic size - in other words, it is always taken around the point cloud’s centre.

By default, the Frobenius norm is taken, but this can be changed by setting kwargs - see numpy.linalg.norm for valid options.

Returns:

norm : float

The norm of this PointCloud

range(boundary=0)[source]

The range of the extent of the PointCloud.

Parameters:

boundary : float

A optional padding distance that is used to extend the bounds from which the range is computed. Default is 0, no extension is performed.

Returns:

range : (n_dims,) ndarray

The range of the PointCloud extent in each dimension.

tojson()[source]

Convert this PointCloud to a dictionary JSON representation.

Returns:

json_dict : dict

Dictionary with a ‘points’ key, the value of which is a list suitable :

for use in the by the `json` standard library package. :

update_from_mask(mask)[source]

A 1D boolean array with the same number of elements as the number of points in the pointcloud. This is then broadcast across the dimensions of the pointcloud. The same pointcloud is updated in place.

Parameters:

mask : (n_points,) ndarray

1D array of booleans

Returns:

pointcloud : PointCloud

A pointer to self.

view(**kwargs)

View the object using the default rendering engine figure handling. For example, the default behaviour for Matplotlib is that all draw commands are applied to the same figure object.

Parameters:

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

view_new(**kwargs)

View the object on a new figure.

Parameters:

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

view_on(figure_id, **kwargs)

View the object on a a specific figure specified by the given id.

Parameters:

figure_id : object

A unique identifier for a figure.

kwargs : dict

Passed through to specific rendering engine.

Returns:

viewer : Renderer

The renderer instantiated.

centre[source]

The mean of all the points in this PointCloud (in the centre of mass sense)

Type:(n_dims) ndarray The mean of this PointCloud’s points.
centre_of_bounds[source]

The centre of the absolute bounds of this PointCloud. Contrast with centre, which is the mean point position.

Type:n_dims ndarray The centre of the bounds of this PointCloud.
h_points[source]

homogeneous points of shape (n_dims + 1, n_points)

n_dims[source]

The number of dimensions in the pointcloud.

Type:int
n_landmark_groups

The number of landmark groups on this object.

Type:int
n_parameters

The length of the vector that this object produces.

Type:int
n_points[source]

The number of points in the pointcloud.

Type:int