imgaug.augmentables.utils¶
Utility functions used in augmentable modules.
-
imgaug.augmentables.utils.convert_cbaois_to_kpsois(cbaois)[source]¶ Convert coordinate-based augmentables to KeypointsOnImage instances.
Added in 0.4.0.
Parameters: cbaois (list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage) – Coordinate-based augmentables to convert, e.g. bounding boxes. Returns: KeypointsOnImageinstances containing the coordinates of input cbaois.Return type: list of imgaug.augmentables.kps.KeypointsOnImage or imgaug.augmentables.kps.KeypointsOnImage
-
imgaug.augmentables.utils.interpolate_point_pair(point_a, point_b, nb_steps)[source]¶ Interpolate
Npoints on a line segment.Parameters: - point_a (iterable of number) – Start point of the line segment, given as
(x,y)coordinates. - point_b (iterable of number) – End point of the line segment, given as
(x,y)coordinates. - nb_steps (int) – Number of points to interpolate between point_a and point_b.
Returns: The interpolated points. Does not include point_a.
Return type: list of tuple of number
- point_a (iterable of number) – Start point of the line segment, given as
-
imgaug.augmentables.utils.interpolate_points(points, nb_steps, closed=True)[source]¶ Interpolate
Non each line segment in a line string.Parameters: - points (iterable of iterable of number) – Points on the line segments, each one given as
(x,y)coordinates. They are assumed to form one connected line string. - nb_steps (int) – Number of points to interpolate on each individual line string.
- closed (bool, optional) – If
Truethe output contains the last point in points. Otherwise it does not (but it will contain the interpolated points leading to the last point).
Returns: Coordinates of points, with additional nb_steps new points interpolated between each point pair. If closed is
False, the last point in points is not returned.Return type: list of tuple of number
- points (iterable of iterable of number) – Points on the line segments, each one given as
-
imgaug.augmentables.utils.interpolate_points_by_max_distance(points, max_distance, closed=True)[source]¶ Interpolate points with distance
don a line string.For a list of points
A, B, C, if the distance betweenAandBis greater than max_distance, it will place at least one point betweenAandBatA + max_distance * (B - A). Multiple points can be placed between the two points if they are far enough away from each other. The process is repeated forBandC.Parameters: - points (iterable of iterable of number) – Points on the line segments, each one given as
(x,y)coordinates. They are assumed to form one connected line string. - max_distance (number) – Maximum distance between any two points in the result.
- closed (bool, optional) – If
Truethe output contains the last point in points. Otherwise it does not (but it will contain the interpolated points leading to the last point).
Returns: Coordinates of points, with interpolated points added to the iterable. If closed is
False, the last point in points is not returned.Return type: list of tuple of number
- points (iterable of iterable of number) – Points on the line segments, each one given as
-
imgaug.augmentables.utils.invert_convert_cbaois_to_kpsois_(cbaois, kpsois)[source]¶ Invert the output of
convert_to_cbaois_to_kpsois()in-place.This function writes in-place into cbaois.
Added in 0.4.0.
Parameters: - cbaois (list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage) – Original coordinate-based augmentables before they were converted,
i.e. the same inputs as provided to
convert_to_kpsois(). - kpsois (list of imgaug.augmentables.kps.KeypointsOnImages or imgaug.augmentables.kps.KeypointsOnImages) – Keypoints to convert back to the types of cbaois, i.e. the outputs
of
convert_cbaois_to_kpsois().
Returns: Parameter cbaois, with updated coordinates and shapes derived from kpsois. cbaois is modified in-place.
Return type: list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage
- cbaois (list of imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.PolygonsOnImage or list of imgaug.augmentables.bbs.LineStringsOnImage or imgaug.augmentables.bbs.BoundingBoxesOnImage or imgaug.augmentables.bbs.PolygonsOnImage or imgaug.augmentables.bbs.LineStringsOnImage) – Original coordinate-based augmentables before they were converted,
i.e. the same inputs as provided to
-
imgaug.augmentables.utils.normalize_shape(shape)[source]¶ Normalize a shape
tupleorarrayto a shapetuple.Parameters: shape (tuple of int or ndarray) – The input to normalize. May optionally be an array. Returns: Shape tuple.Return type: tuple of int
-
imgaug.augmentables.utils.project_coords(coords, from_shape, to_shape)[source]¶ Project coordinates from one image shape to another.
This performs a relative projection, e.g. a point at
60%of the old image width will be at60%of the new image width after projection.Parameters: - coords (ndarray or list of tuple of number) – Coordinates to project.
Either an
(N,2)numpy array or alistcontaining(x,y)coordinatetuples. - from_shape (tuple of int or ndarray) – Old image shape.
- to_shape (tuple of int or ndarray) – New image shape.
Returns: Projected coordinates as
(N,2)float32numpy array.Return type: ndarray
- coords (ndarray or list of tuple of number) – Coordinates to project.
Either an
-
imgaug.augmentables.utils.project_coords_(coords, from_shape, to_shape)[source]¶ Project coordinates from one image shape to another in-place.
This performs a relative projection, e.g. a point at
60%of the old image width will be at60%of the new image width after projection.Added in 0.4.0.
Parameters: - coords (ndarray or list of tuple of number) – Coordinates to project.
Either an
(N,2)numpy array or alistcontaining(x,y)coordinatetuples. - from_shape (tuple of int or ndarray) – Old image shape.
- to_shape (tuple of int or ndarray) – New image shape.
Returns: Projected coordinates as
(N,2)float32numpy array. This function may change the input data in-place.Return type: ndarray
- coords (ndarray or list of tuple of number) – Coordinates to project.
Either an