imgaug.augmentables.kps¶
Classes to represent keypoints, i.e. points given as xy-coordinates.
-
class
imgaug.augmentables.kps.
Keypoint
(x, y)[source]¶ Bases:
object
A single keypoint (aka landmark) on an image.
Parameters: - x (number) – Coordinate of the keypoint on the x axis.
- y (number) – Coordinate of the keypoint on the y axis.
Attributes: coords
Get the xy-coordinates as an
(N,2)
ndarray.x_int
Get the keypoint’s x-coordinate, rounded to the closest integer.
xy
Get the keypoint’s x- and y-coordinate as a single array.
xy_int
Get the keypoint’s xy-coord, rounded to closest integer.
y_int
Get the keypoint’s y-coordinate, rounded to the closest integer.
Methods
almost_equals
(self, other[, max_distance])Compare this and another KP’s coordinates. compute_out_of_image_fraction
(self, image)Compute fraction of the keypoint that is out of the image plane. coords_almost_equals
(self, other[, max_distance])Estimate if this and another KP have almost identical coordinates. copy
(self[, x, y])Create a shallow copy of the keypoint instance. deepcopy
(self[, x, y])Create a deep copy of the keypoint instance. draw_on_image
(self, image[, color, alpha, …])Draw the keypoint onto a given image. generate_similar_points_manhattan
(self, …)Generate nearby points based on manhattan distance. is_out_of_image
(self, image)Estimate whether this point is outside of the given image plane. project
(self, from_shape, to_shape)Project the keypoint onto a new position on a new image. project_
(self, from_shape, to_shape)Project in-place the keypoint onto a new position on a new image. shift
(self[, x, y])Move the keypoint around on an image. shift_
(self[, x, y])Move the keypoint around on an image in-place. -
almost_equals
(self, other, max_distance=0.0001)[source]¶ Compare this and another KP’s coordinates.
Note
This method is currently identical to
coords_almost_equals
. It exists for consistency withBoundingBox
andPolygons
.Added in 0.4.0.
Parameters: - other (imgaug.augmentables.kps.Keypoint or iterable) – The other object to compare against. Expected to be a
Keypoint
. - max_distance (number, optional) – See
coords_almost_equals()
.
Returns: True
if the coordinates are almost equal. OtherwiseFalse
.Return type: bool
- other (imgaug.augmentables.kps.Keypoint or iterable) – The other object to compare against. Expected to be a
-
compute_out_of_image_fraction
(self, image)[source]¶ Compute fraction of the keypoint that is out of the image plane.
The fraction is always either
1.0
(point is outside of the image plane) or0.0
(point is inside the image plane). This method exists for consistency with other augmentables, e.g. bounding boxes.Added in 0.4.0.
Parameters: image ((H,W,…) ndarray or tuple of int) – Image dimensions to use. If an ndarray
, its shape will be used. If atuple
, it is assumed to represent the image shape and must contain at least two integers.Returns: Either 1.0
(point is outside of the image plane) or0.0
(point is inside of it).Return type: float
-
coords
¶ Get the xy-coordinates as an
(N,2)
ndarray.Added in 0.4.0.
Returns: An (N, 2)
float32
ndarray withN=1
containing the coordinates of this keypoints.Return type: ndarray
-
coords_almost_equals
(self, other, max_distance=0.0001)[source]¶ Estimate if this and another KP have almost identical coordinates.
Added in 0.4.0.
Parameters: - other (imgaug.augmentables.kps.Keypoint or iterable) – The other keypoint with which to compare this one.
If this is an
iterable
, it is assumed to contain the xy-coordinates of a keypoint. - max_distance (number, optional) – The maximum euclidean distance between a this keypoint and the other one. If the distance is exceeded, the two keypoints are not viewed as equal.
Returns: Whether the two keypoints have almost identical coordinates.
Return type: bool
- other (imgaug.augmentables.kps.Keypoint or iterable) – The other keypoint with which to compare this one.
If this is an
-
copy
(self, x=None, y=None)[source]¶ Create a shallow copy of the keypoint instance.
Parameters: - x (None or number, optional) – Coordinate of the keypoint on the x axis.
If
None
, the instance’s value will be copied. - y (None or number, optional) – Coordinate of the keypoint on the y axis.
If
None
, the instance’s value will be copied.
Returns: Shallow copy.
Return type: - x (None or number, optional) – Coordinate of the keypoint on the x axis.
If
-
deepcopy
(self, x=None, y=None)[source]¶ Create a deep copy of the keypoint instance.
Parameters: - x (None or number, optional) – Coordinate of the keypoint on the x axis.
If
None
, the instance’s value will be copied. - y (None or number, optional) – Coordinate of the keypoint on the y axis.
If
None
, the instance’s value will be copied.
Returns: Deep copy.
Return type: - x (None or number, optional) – Coordinate of the keypoint on the x axis.
If
-
draw_on_image
(self, image, color=(0, 255, 0), alpha=1.0, size=3, copy=True, raise_if_out_of_image=False)[source]¶ Draw the keypoint onto a given image.
The keypoint is drawn as a square.
Parameters: - image ((H,W,3) ndarray) – The image onto which to draw the keypoint.
- color (int or list of int or tuple of int or (3,) ndarray, optional) – The RGB color of the keypoint.
If a single
int
C
, then that is equivalent to(C,C,C)
. - alpha (float, optional) – The opacity of the drawn keypoint, where
1.0
denotes a fully visible keypoint and0.0
an invisible one. - size (int, optional) – The size of the keypoint. If set to
S
, each square will have sizeS x S
. - copy (bool, optional) – Whether to copy the image before drawing the keypoint.
- raise_if_out_of_image (bool, optional) – Whether to raise an exception if the keypoint is outside of the image.
Returns: image – Image with drawn keypoint.
Return type: (H,W,3) ndarray
-
generate_similar_points_manhattan
(self, nb_steps, step_size, return_array=False)[source]¶ Generate nearby points based on manhattan distance.
To generate the first neighbouring points, a distance of
S
(step size) is moved from the center point (this keypoint) to the top, right, bottom and left, resulting in four new points. From these new points, the pattern is repeated. Overlapping points are ignored.The resulting points have a shape similar to a square rotated by
45
degrees.Parameters: - nb_steps (int) – The number of steps to move from the center point.
nb_steps=1
results in a total of5
output points (one center point + four neighbours). - step_size (number) – The step size to move from every point to its neighbours.
- return_array (bool, optional) – Whether to return the generated points as a list of
Keypoint
or an array of shape(N,2)
, whereN
is the number of generated points and the second axis contains the x-/y-coordinates.
Returns: If return_array was
False
, then a list ofKeypoint
. Otherwise a numpy array of shape(N,2)
, whereN
is the number of generated points and the second axis contains the x-/y-coordinates. The center keypoint (the one on which this function was called) is always included.Return type: list of imgaug.augmentables.kps.Keypoint or (N,2) ndarray
- nb_steps (int) – The number of steps to move from the center point.
-
is_out_of_image
(self, image)[source]¶ Estimate whether this point is outside of the given image plane.
Added in 0.4.0.
Parameters: image ((H,W,…) ndarray or tuple of int) – Image dimensions to use. If an ndarray
, its shape will be used. If atuple
, it is assumed to represent the image shape and must contain at least two integers.Returns: True
is the point is inside the image plane,False
otherwise.Return type: bool
-
project
(self, from_shape, to_shape)[source]¶ Project the keypoint onto a new position on a new image.
E.g. if the keypoint is on its original image at
x=(10 of 100 pixels)
andy=(20 of 100 pixels)
and is projected onto a new image with size(width=200, height=200)
, its new position will be(20, 40)
.This is intended for cases where the original image is resized. It cannot be used for more complex changes (e.g. padding, cropping).
Parameters: - from_shape (tuple of int) – Shape of the original image. (Before resize.)
- to_shape (tuple of int) – Shape of the new image. (After resize.)
Returns: Keypoint object with new coordinates.
Return type:
-
project_
(self, from_shape, to_shape)[source]¶ Project in-place the keypoint onto a new position on a new image.
E.g. if the keypoint is on its original image at
x=(10 of 100 pixels)
andy=(20 of 100 pixels)
and is projected onto a new image with size(width=200, height=200)
, its new position will be(20, 40)
.This is intended for cases where the original image is resized. It cannot be used for more complex changes (e.g. padding, cropping).
Added in 0.4.0.
Parameters: - from_shape (tuple of int) – Shape of the original image. (Before resize.)
- to_shape (tuple of int) – Shape of the new image. (After resize.)
Returns: Keypoint object with new coordinates. The instance of the keypoint may have been modified in-place.
Return type:
-
shift
(self, x=0, y=0)[source]¶ Move the keypoint around on an image.
Parameters: - x (number, optional) – Move by this value on the x axis.
- y (number, optional) – Move by this value on the y axis.
Returns: Keypoint object with new coordinates.
Return type:
-
shift_
(self, x=0, y=0)[source]¶ Move the keypoint around on an image in-place.
Added in 0.4.0.
Parameters: - x (number, optional) – Move by this value on the x axis.
- y (number, optional) – Move by this value on the y axis.
Returns: Keypoint object with new coordinates. The instance of the keypoint may have been modified in-place.
Return type:
-
x_int
¶ Get the keypoint’s x-coordinate, rounded to the closest integer.
Returns: result – Keypoint’s x-coordinate, rounded to the closest integer. Return type: int
-
xy
¶ Get the keypoint’s x- and y-coordinate as a single array.
Added in 0.4.0.
Returns: A (2,)
ndarray
denoting the xy-coordinate pair.Return type: ndarray
-
xy_int
¶ Get the keypoint’s xy-coord, rounded to closest integer.
Added in 0.4.0.
Returns: A (2,)
ndarray
denoting the xy-coordinate pair.Return type: ndarray
-
y_int
¶ Get the keypoint’s y-coordinate, rounded to the closest integer.
Returns: result – Keypoint’s y-coordinate, rounded to the closest integer. Return type: int
-
class
imgaug.augmentables.kps.
KeypointsOnImage
(keypoints, shape)[source]¶ Bases:
imgaug.augmentables.base.IAugmentable
Container for all keypoints on a single image.
Parameters: - keypoints (list of imgaug.augmentables.kps.Keypoint) – List of keypoints on the image.
- shape (tuple of int or ndarray) – The shape of the image on which the objects are placed.
Either an image with shape
(H,W,[C])
or atuple
denoting such an image shape.
Examples
>>> import numpy as np >>> from imgaug.augmentables.kps import Keypoint, KeypointsOnImage >>> >>> image = np.zeros((70, 70)) >>> kps = [Keypoint(x=10, y=20), Keypoint(x=34, y=60)] >>> kps_oi = KeypointsOnImage(kps, shape=image.shape)
Attributes: Methods
clip_out_of_image
(self)Remove all KPs that are outside of the image plane. clip_out_of_image_
(self)Remove all KPs that are outside of the image plane. copy
(self[, keypoints, shape])Create a shallow copy of the KeypointsOnImage
object.deepcopy
(self[, keypoints, shape])Create a deep copy of the KeypointsOnImage
object.draw_on_image
(self, image[, color, alpha, …])Draw all keypoints onto a given image. fill_from_xy_array_
(self, xy)Modify the keypoint coordinates of this instance in-place. from_coords_array
(coords, shape)Deprecated. from_distance_maps
(distance_maps[, …])Convert outputs of to_distance_maps()
toKeypointsOnImage
.from_keypoint_image
(image[, …])Convert to_keypoint_image()
outputs toKeypointsOnImage
.from_xy_array
(xy, shape)Convert an (N,2)
array to aKeypointsOnImage
object.get_coords_array
(self)Deprecated. invert_to_keypoints_on_image_
(self, kpsoi)Invert the output of to_keypoints_on_image()
in-place.on
(self, image)Project all keypoints from one image shape to a new one. on_
(self, image)Project all keypoints from one image shape to a new one in-place. remove_out_of_image_fraction
(self, fraction)Remove all KPs with an out of image fraction of at least fraction. remove_out_of_image_fraction_
(self, fraction)Remove all KPs with an OOI fraction of at least fraction in-place. shift
(self[, x, y])Move the keypoints on the x/y-axis. shift_
(self[, x, y])Move the keypoints on the x/y-axis in-place. to_distance_maps
(self[, inverted])Generate a (H,W,N)
array of distance maps forN
keypoints.to_keypoint_image
(self[, size])Create an (H,W,N)
image with keypoint coordinates set to255
.to_keypoints_on_image
(self)Convert the keypoints to one KeypointsOnImage
instance.to_xy_array
(self)Convert all keypoint coordinates to an array of shape (N,2)
.-
clip_out_of_image
(self)[source]¶ Remove all KPs that are outside of the image plane.
This method exists for consistency with other augmentables, e.g. bounding boxes.
Added in 0.4.0.
Returns: Keypoints that are inside the image plane. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
clip_out_of_image_
(self)[source]¶ Remove all KPs that are outside of the image plane.
This method exists for consistency with other augmentables, e.g. bounding boxes.
Added in 0.4.0.
Returns: Keypoints that are inside the image plane. The object may have been modified in-place. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
copy
(self, keypoints=None, shape=None)[source]¶ Create a shallow copy of the
KeypointsOnImage
object.Parameters: - keypoints (None or list of imgaug.Keypoint, optional) – List of keypoints on the image.
If
None
, the instance’s keypoints will be copied. - shape (tuple of int, optional) – The shape of the image on which the keypoints are placed.
If
None
, the instance’s shape will be copied.
Returns: Shallow copy.
Return type: - keypoints (None or list of imgaug.Keypoint, optional) – List of keypoints on the image.
If
-
deepcopy
(self, keypoints=None, shape=None)[source]¶ Create a deep copy of the
KeypointsOnImage
object.Parameters: - keypoints (None or list of imgaug.Keypoint, optional) – List of keypoints on the image.
If
None
, the instance’s keypoints will be copied. - shape (tuple of int, optional) – The shape of the image on which the keypoints are placed.
If
None
, the instance’s shape will be copied.
Returns: Deep copy.
Return type: - keypoints (None or list of imgaug.Keypoint, optional) – List of keypoints on the image.
If
-
draw_on_image
(self, image, color=(0, 255, 0), alpha=1.0, size=3, copy=True, raise_if_out_of_image=False)[source]¶ Draw all keypoints onto a given image.
Each keypoint is drawn as a square of provided color and size.
Parameters: - image ((H,W,3) ndarray) – The image onto which to draw the keypoints.
This image should usually have the same shape as
set in
KeypointsOnImage.shape
. - color (int or list of int or tuple of int or (3,) ndarray, optional) – The RGB color of all keypoints.
If a single
int
C
, then that is equivalent to(C,C,C)
. - alpha (float, optional) – The opacity of the drawn keypoint, where
1.0
denotes a fully visible keypoint and0.0
an invisible one. - size (int, optional) – The size of each point. If set to
C
, each square will have sizeC x C
. - copy (bool, optional) – Whether to copy the image before drawing the points.
- raise_if_out_of_image (bool, optional) – Whether to raise an exception if any keypoint is outside of the image.
Returns: Image with drawn keypoints.
Return type: (H,W,3) ndarray
- image ((H,W,3) ndarray) – The image onto which to draw the keypoints.
This image should usually have the same shape as
set in
-
empty
¶ Determine whether this object contains zero keypoints.
Returns: True
if this object contains zero keypoints.Return type: bool
-
fill_from_xy_array_
(self, xy)[source]¶ Modify the keypoint coordinates of this instance in-place.
Note
This currently expects that xy contains exactly as many coordinates as there are keypoints in this instance. Otherwise, an
AssertionError
will be raised.Added in 0.4.0.
Parameters: xy ((N, 2) ndarray or iterable of iterable of number) – Coordinates of N
keypoints on an image, given as a(N,2)
array of xy-coordinates.N
must match the number of keypoints in this instance.Returns: This instance itself, with updated keypoint coordinates. Note that the instance was modified in-place. Return type: KeypointsOnImage
-
static
from_coords_array
(coords, shape)[source]¶ Deprecated. Use
KeypointsOnImage.from_xy_array()
instead.Convert an
(N,2)
array to aKeypointsOnImage
object.Parameters: - coords : (N, 2) ndarray
Coordinates of
N
keypoints on an image, given as a(N,2)
array of xy-coordinates.- shape : tuple
The shape of the image on which the keypoints are placed.
Returns: - imgaug.augmentables.kps.KeypointsOnImage
KeypointsOnImage
object containing the array’s keypoints.
-
static
from_distance_maps
(distance_maps, inverted=False, if_not_found_coords={'x': -1, 'y': -1}, threshold=None, nb_channels=None)[source]¶ Convert outputs of
to_distance_maps()
toKeypointsOnImage
.This is the inverse of
KeypointsOnImage.to_distance_maps()
.Parameters: - distance_maps ((H,W,N) ndarray) – The distance maps.
N
is the number of keypoints. - inverted (bool, optional) – Whether the given distance maps were generated in inverted mode
(i.e.
KeypointsOnImage.to_distance_maps()
was called withinverted=True
) or in non-inverted mode. - if_not_found_coords (tuple or list or dict or None, optional) – Coordinates to use for keypoints that cannot be found
in distance_maps.
- If this is a
list
/tuple
, it must contain twoint
values. - If it is a
dict
, it must contain the keysx
andy
with each containing oneint
value. - If this is
None
, then the keypoint will not be added to the finalKeypointsOnImage
object.
- If this is a
- threshold (float, optional) – The search for keypoints works by searching for the
argmin (non-inverted) or argmax (inverted) in each channel. This
parameters contains the maximum (non-inverted) or
minimum (inverted) value to accept in order to view a hit as a
keypoint. Use
None
to use no min/max. - nb_channels (None or int, optional) – Number of channels of the image on which the keypoints are placed.
Some keypoint augmenters require that information.
If set to
None
, the keypoint’s shape will be set to(height, width)
, otherwise(height, width, nb_channels)
.
Returns: The extracted keypoints.
Return type: - distance_maps ((H,W,N) ndarray) – The distance maps.
-
static
from_keypoint_image
(image, if_not_found_coords={'x': -1, 'y': -1}, threshold=1, nb_channels=None)[source]¶ Convert
to_keypoint_image()
outputs toKeypointsOnImage
.This is the inverse of
KeypointsOnImage.to_keypoint_image()
.Parameters: - image ((H,W,N) ndarray) – The keypoints image. N is the number of keypoints.
- if_not_found_coords (tuple or list or dict or None, optional) – Coordinates to use for keypoints that cannot be found in image.
- If this is a
list
/tuple
, it must contain twoint
values. - If it is a
dict
, it must contain the keysx
andy
with each containing oneint
value. - If this is
None
, then the keypoint will not be added to the finalKeypointsOnImage
object.
- If this is a
- threshold (int, optional) – The search for keypoints works by searching for the argmax in each channel. This parameters contains the minimum value that the max must have in order to be viewed as a keypoint.
- nb_channels (None or int, optional) – Number of channels of the image on which the keypoints are placed.
Some keypoint augmenters require that information.
If set to
None
, the keypoint’s shape will be set to(height, width)
, otherwise(height, width, nb_channels)
.
Returns: The extracted keypoints.
Return type:
-
classmethod
from_xy_array
(xy, shape)[source]¶ Convert an
(N,2)
array to aKeypointsOnImage
object.Parameters: - xy ((N, 2) ndarray or iterable of iterable of number) – Coordinates of
N
keypoints on an image, given as a(N,2)
array of xy-coordinates. - shape (tuple of int or ndarray) – The shape of the image on which the keypoints are placed.
Returns: KeypointsOnImage
object containing the array’s keypoints.Return type: - xy ((N, 2) ndarray or iterable of iterable of number) – Coordinates of
-
get_coords_array
(self)[source]¶ Deprecated. Use
KeypointsOnImage.to_xy_array()
instead.Convert all keypoint coordinates to an array of shape
(N,2)
.Returns: - (N, 2) ndarray
Array containing the coordinates of all keypoints.
N
denotes the number of keypoints. The second axis denotes the x/y-coordinates.
-
height
¶ Get the image height.
Returns: Image height. Return type: int
-
invert_to_keypoints_on_image_
(self, kpsoi)[source]¶ Invert the output of
to_keypoints_on_image()
in-place.This function writes in-place into this
KeypointsOnImage
instance.Added in 0.4.0.
Parameters: kpsoi (imgaug.augmentables.kps.KeypointsOnImages) – Keypoints to copy data from, i.e. the outputs of to_keypoints_on_image()
.Returns: Keypoints container with updated coordinates. Note that the instance is also updated in-place. Return type: KeypointsOnImage
-
items
¶ Get the keypoints in this container.
Added in 0.4.0.
Returns: Keypoints within this container. Return type: list of Keypoint
-
on
(self, image)[source]¶ Project all keypoints from one image shape to a new one.
Parameters: image (ndarray or tuple of int) – New image onto which the keypoints are to be projected. May also simply be that new image’s shape tuple. Returns: Object containing all projected keypoints. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
on_
(self, image)[source]¶ Project all keypoints from one image shape to a new one in-place.
Added in 0.4.0.
Parameters: image (ndarray or tuple of int) – New image onto which the keypoints are to be projected. May also simply be that new image’s shape tuple. Returns: Object containing all projected keypoints. The object may have been modified in-place. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
remove_out_of_image_fraction
(self, fraction)[source]¶ Remove all KPs with an out of image fraction of at least fraction.
This method exists for consistency with other augmentables, e.g. bounding boxes.
Added in 0.4.0.
Parameters: fraction (number) – Minimum out of image fraction that a keypoint has to have in order to be removed. Note that any keypoint can only have a fraction of either 1.0
(is outside) or0.0
(is inside). Set this to0.0+eps
to remove all points that are outside of the image. Setting this to0.0
will remove all points.Returns: Reduced set of keypoints, with those thathad an out of image fraction greater or equal the given one removed. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
remove_out_of_image_fraction_
(self, fraction)[source]¶ Remove all KPs with an OOI fraction of at least fraction in-place.
‘OOI’ is the abbreviation for ‘out of image’.
This method exists for consistency with other augmentables, e.g. bounding boxes.
Added in 0.4.0.
Parameters: fraction (number) – Minimum out of image fraction that a keypoint has to have in order to be removed. Note that any keypoint can only have a fraction of either 1.0
(is outside) or0.0
(is inside). Set this to0.0+eps
to remove all points that are outside of the image. Setting this to0.0
will remove all points.Returns: Reduced set of keypoints, with those thathad an out of image fraction greater or equal the given one removed. The object may have been modified in-place. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
shift
(self, x=0, y=0)[source]¶ Move the keypoints on the x/y-axis.
Parameters: - x (number, optional) – Move each keypoint by this value on the x axis.
- y (number, optional) – Move each keypoint by this value on the y axis.
Returns: Keypoints after moving them.
Return type:
-
shift_
(self, x=0, y=0)[source]¶ Move the keypoints on the x/y-axis in-place.
Added in 0.4.0.
Parameters: - x (number, optional) – Move each keypoint by this value on the x axis.
- y (number, optional) – Move each keypoint by this value on the y axis.
Returns: Keypoints after moving them. The object and its items may have been modified in-place.
Return type:
-
to_distance_maps
(self, inverted=False)[source]¶ Generate a
(H,W,N)
array of distance maps forN
keypoints.The
n
-th distance map contains at every location(y, x)
the euclidean distance to then
-th keypoint.This function can be used as a helper when augmenting keypoints with a method that only supports the augmentation of images.
Parameters: inverted (bool, optional) – If True
, inverted distance maps are returned where each distance value d is replaced byd/(d+1)
, i.e. the distance maps have values in the range(0.0, 1.0]
with1.0
denoting exactly the position of the respective keypoint.Returns: A float32
array containingN
distance maps forN
keypoints. Each location(y, x, n)
in the array denotes the euclidean distance at(y, x)
to then
-th keypoint. If inverted isTrue
, the distanced
is replaced byd/(d+1)
. The height and width of the array match the height and width inKeypointsOnImage.shape
.Return type: (H,W,N) ndarray
-
to_keypoint_image
(self, size=1)[source]¶ Create an
(H,W,N)
image with keypoint coordinates set to255
.This method generates a new
uint8
array of shape(H,W,N)
, whereH
is the.shape
height,W
the.shape
width andN
is the number of keypoints. The array is filled with zeros. The coordinate of then
-th keypoint is set to255
in then
-th channel.This function can be used as a helper when augmenting keypoints with a method that only supports the augmentation of images.
Parameters: size (int) – Size of each (squared) point. Returns: Image in which the keypoints are marked. H
is the height, defined inKeypointsOnImage.shape[0]
(analogousW
).N
is the number of keypoints.Return type: (H,W,N) ndarray
-
to_keypoints_on_image
(self)[source]¶ Convert the keypoints to one
KeypointsOnImage
instance.This method exists for consistency with
BoundingBoxesOnImage
,PolygonsOnImage
andLineStringsOnImage
.Added in 0.4.0.
Returns: Copy of this keypoints instance. Return type: imgaug.augmentables.kps.KeypointsOnImage
-
to_xy_array
(self)[source]¶ Convert all keypoint coordinates to an array of shape
(N,2)
.Returns: Array containing the coordinates of all keypoints. N
denotes the number of keypoints. The second axis denotes the x/y-coordinates.Return type: (N, 2) ndarray
-
width
¶ Get the image width.
Returns: Image width. Return type: int
-
imgaug.augmentables.kps.
compute_geometric_median
(points=None, eps=1e-05, X=None)[source]¶ Estimate the geometric median of points in 2D.
Code from https://stackoverflow.com/a/30305181
Parameters: - points ((N,2) ndarray) – Points in 2D. Second axis must be given in xy-form.
- eps (float, optional) – Distance threshold when to return the median.
- X (None or (N,2) ndarray, optional) – Deprecated.
Returns: Geometric median as xy-coordinate.
Return type: (2,) ndarray