PointGraph¶
-
class
menpo.shape.
PointGraph
(points, adjacency_array, copy=True)[source]¶ Bases:
Graph
,PointCloud
Class for defining a graph with geometry.
Parameters: - points (ndarray) – The array of point locations.
- adjacency_array (
(n_edges, 2, )
ndarray) –The adjacency array of the graph, i.e. an array containing the sets of the graph’s edges. The numbering of vertices is assumed to start from 0.
For an undirected graph, the order of an edge’s vertices doesn’t matter, for example
|---0---| adjacency_array = ndarray([[0, 1], | | [0, 2], | | [1, 2], 1-------2 [1, 3], | | [2, 4], | | [3, 4], 3-------4 [3, 5]]) | 5
For a directed graph, we assume that the vertices in the first column of the
adjacency_array
are the fathers and the vertices in the second column of theadjacency_array
are the children, for example|-->0<--| adjacency_array = ndarray([[1, 0], | | [2, 0], | | [1, 2], 1<----->2 [2, 1], | | [1, 3], v v [2, 4], 3------>4 [3, 4], | [3, 5]]) v 5
-
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.
-
bounding_box
()¶ Return the bounding box of this PointCloud as a directed graph. The the first point (0) will be nearest the origin for an axis aligned Pointcloud. In the case of an image, this ordering would appear as:
0<--3 | ^ | | v | 1-->2
Returns: bounding_box ( PointDirectedGraph
) – The axis aligned bounding box of the PointCloud.
-
bounds
(boundary=0)¶ 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 thePointCloud
and boundary along each dimension - max_b (
(n_dims,)
ndarray) – The maximum extent of thePointCloud
and boundary along each dimension
- min_b (
-
centre
()¶ The mean of all the points in this PointCloud (centre of mass).
Returns: centre ( (n_dims)
ndarray) – The mean of this PointCloud’s points.
-
centre_of_bounds
()¶ The centre of the absolute bounds of this PointCloud. Contrast with
centre()
, which is the mean point position.Returns: centre ( n_dims
ndarray) – The centre of the bounds of this PointCloud.
-
copy
()¶ Generate an efficient copy of this object.
Note that Numpy arrays and other
Copyable
objects onself
will be deeply copied. Dictionaries and sets will be shallow copied, and everything else will be assigned (no copy will be made).Classes that store state other than numpy arrays and immutable types should overwrite this method to ensure all state is copied.
Returns: type(self)
– A copy of this object
-
distance_to
(pointcloud, **kwargs)¶ Returns a distance matrix between this PointCloud and another. By default the Euclidean 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.
-
find_all_paths
(start, end, path=[])¶ Returns a list of lists with all the paths (without cycles) found from start vertex to end vertex.
Parameters: - start (int) – The vertex from which the paths start.
- end (int) – The vertex from which the paths end.
- path (list, optional) – An existing path to append to.
Returns: paths (list of list) – The list containing all the paths from start to end.
-
find_path
(start, end, path=None)¶ Returns a list with the first path (without cycles) found from start vertex to end vertex.
Parameters: - start (int) – The vertex from which the path starts.
- end (int) – The vertex from which the path ends.
- path (list, optional) – An existing path to append to.
Returns: path (list) – The path’s vertices.
-
find_shortest_path
(start, end, path=None)¶ Returns a list with the shortest path (without cycles) found from start vertex to end vertex.
Parameters: - start (int) – The vertex from which the path starts.
- end (int) – The vertex from which the path ends.
- path (list, optional) – An existing path to append to.
Returns: path (list) – The shortest path’s vertices.
-
from_mask
(mask)¶ 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 booleansReturns: pointcloud ( PointCloud
) – A new pointcloud that has been masked.Raises: ValueError
– Mask must have same number of points as pointcloud.
-
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 adeepcopy
of the object followed by a call tofrom_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)¶ Updates the points of this PointCloud in-place with the reshaped points from the provided vector. Note that the vector should have the form
[x0, y0, x1, y1, ....., xn, yn]
for 2D.Parameters: vector ( (n_points,)
ndarray) – The vector from which to create the points’ array.
-
get_adjacency_matrix
()¶ Returns the adjacency matrix of the graph, i.e. the boolean ndarray that is
True
andFalse
if there is an edge connecting the two vertices or not respectively.Type: (n_vertices, n_vertices, )
ndarray
-
h_points
()¶ Convert poincloud to a homogeneous array:
(n_dims + 1, n_points)
Type: type(self)
-
has_cycles
()¶ Checks if the graph has at least one cycle.
Returns: has_cycles (bool) – If the graph has cycles.
-
is_tree
()¶ Checks if the graph is tree.
Returns: is_true (bool) – If the graph is a tree.
-
n_paths
(start, end)¶ Returns the number of all the paths (without cycles) existing from start vertex to end vertex.
Parameters: - start (int) – The vertex from which the paths start.
- end (int) – The vertex from which the paths end.
Returns: paths (int) – The paths’ numbers.
-
norm
(**kwargs)¶ Returns the norm of this PointCloud. 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)¶ 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 thePointCloud
extent in each dimension.
-
tojson
()[source]¶ Convert this
PointGraph
to a dictionary representation suitable for inclusion in the LJSON landmark format.Returns: json (dict) – Dictionary with points
andconnectivity
keys.
-
view_widget
(popup=False, browser_style='buttons', figure_size=(10, 8))[source]¶ Visualization of the PointGraph using the
visualize_pointclouds
widget.Parameters: - popup (bool, optional) – If
True
, the widget will be rendered in a popup window. - browser_style (
{buttons, slider}
, optional) – It defines whether the selector of the PointGraph objects will have the form of plus/minus buttons or a slider. - figure_size ((int, int) tuple, optional) – The initial size of the rendered figure.
- popup (bool, optional) – If
-
has_landmarks
¶ Whether the object has landmarks.
Type: bool
-
landmarks
¶ The landmarks object.
Type: LandmarkManager
-
n_dims
¶ The number of dimensions in the pointcloud.
Type: int
-
n_edges
¶ Returns the number of the graph edges.
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
¶ The number of points in the pointcloud.
Type: int
-
n_vertices
¶ Returns the number of the graph vertices.
Type: int