if isinstance(other, tuple):<EOL><INDENT>x, y = other<EOL><DEDENT>else:<EOL><INDENT>x, y = other.x, other.y<EOL><DEDENT>return self.x1 <= x <= self.x2 and self.y1 <= y <= self.y2<EOL>

Estimate whether the bounding box contains a point.

Parameters
----------
other : tuple of number or imgaug.Keypoint
    Point to check for.

Returns
-------
bool
    True if the point is contained in the bounding box, False otherwise.


def project(self, from_shape, to_shape):

coords_proj = project_coords([(self.x1, self.y1), (self.x2, self.y2)],<EOL>from_shape, to_shape)<EOL>return self.copy(<EOL>x1=coords_proj[<NUM_LIT:0>][<NUM_LIT:0>],<EOL>y1=coords_proj[<NUM_LIT:0>][<NUM_LIT:1>],<EOL>x2=coords_proj[<NUM_LIT:1>][<NUM_LIT:0>],<EOL>y2=coords_proj[<NUM_LIT:1>][<NUM_LIT:1>],<EOL>label=self.label)<EOL>

Project the bounding box onto a differently shaped image.

E.g. if the bounding box is on its original image at
x1=(10 of 100 pixels) and y1=(20 of 100 pixels) and is projected onto
a new image with size (width=200, height=200), its new position will
be (x1=20, y1=40). (Analogous for x2/y2.)

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 or ndarray
    Shape of the original image. (Before resize.)

to_shape : tuple of int or ndarray
    Shape of the new image. (After resize.)

Returns
-------
out : imgaug.BoundingBox
    BoundingBox object with new coordinates.


def extend(self, all_sides=<NUM_LIT:0>, top=<NUM_LIT:0>, right=<NUM_LIT:0>, bottom=<NUM_LIT:0>, left=<NUM_LIT:0>):

return BoundingBox(<EOL>x1=self.x1 - all_sides - left,<EOL>x2=self.x2 + all_sides + right,<EOL>y1=self.y1 - all_sides - top,<EOL>y2=self.y2 + all_sides + bottom<EOL>)<EOL>

Extend the size of the bounding box along its sides.

Parameters
----------
all_sides : number, optional
    Value by which to extend the bounding box size along all sides.

top : number, optional
    Value by which to extend the bounding box size along its top side.

right : number, optional
    Value by which to extend the bounding box size along its right side.

bottom : number, optional
    Value by which to extend the bounding box size along its bottom side.

left : number, optional
    Value by which to extend the bounding box size along its left side.

Returns
-------
imgaug.BoundingBox
    Extended bounding box.


def intersection(self, other, default=None):

x1_i = max(self.x1, other.x1)<EOL>y1_i = max(self.y1, other.y1)<EOL>x2_i = min(self.x2, other.x2)<EOL>y2_i = min(self.y2, other.y2)<EOL>if x1_i > x2_i or y1_i > y2_i:<EOL><INDENT>return default<EOL><DEDENT>else:<EOL><INDENT>return BoundingBox(x1=x1_i, y1=y1_i, x2=x2_i, y2=y2_i)<EOL><DEDENT>

Compute the intersection bounding box of this bounding box and another one.

Note that in extreme cases, the intersection can be a single point, meaning that the intersection bounding box
will exist, but then also has a height and width of zero.

Parameters
----------
other : imgaug.BoundingBox
    Other bounding box with which to generate the intersection.

default : any, optional
    Default value to return if there is no intersection.

Returns
-------
imgaug.BoundingBox or any
    Intersection bounding box of the two bounding boxes if there is an intersection.
    If there is no intersection, the default value will be returned, which can by anything.


return BoundingBox(<EOL>x1=min(self.x1, other.x1),<EOL>y1=min(self.y1, other.y1),<EOL>x2=max(self.x2, other.x2),<EOL>y2=max(self.y2, other.y2),<EOL>)<EOL>

Compute the union bounding box of this bounding box and another one.

This is equivalent to drawing a bounding box around all corners points of both
bounding boxes.

Parameters
----------
other : imgaug.BoundingBox
    Other bounding box with which to generate the union.

Returns
-------
imgaug.BoundingBox
    Union bounding box of the two bounding boxes.


inters = self.intersection(other)<EOL>if inters is None:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>else:<EOL><INDENT>area_union = self.area + other.area - inters.area<EOL>return inters.area / area_union if area_union > <NUM_LIT:0> else <NUM_LIT:0.0><EOL><DEDENT>

Compute the IoU of this bounding box with another one.

IoU is the intersection over union, defined as::

    ``area(intersection(A, B)) / area(union(A, B))``
    ``= area(intersection(A, B)) / (area(A) + area(B) - area(intersection(A, B)))``

Parameters
----------
other : imgaug.BoundingBox
    Other bounding box with which to compare.

Returns
-------
float
    IoU between the two bounding boxes.


shape = normalize_shape(image)<EOL>height, width = shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>return self.x1 >= <NUM_LIT:0> and self.x2 < width and self.y1 >= <NUM_LIT:0> and self.y2 < height<EOL>

Estimate whether the bounding box is fully inside the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape
    and must contain at least two integers.

Returns
-------
bool
    True if the bounding box is fully inside the image area. False otherwise.


shape = normalize_shape(image)<EOL>height, width = shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>eps = np.finfo(np.float32).eps<EOL>img_bb = BoundingBox(x1=<NUM_LIT:0>, x2=width-eps, y1=<NUM_LIT:0>, y2=height-eps)<EOL>return self.intersection(img_bb) is not None<EOL>

Estimate whether the bounding box is at least partially inside the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape
    and must contain at least two integers.

Returns
-------
bool
    True if the bounding box is at least partially inside the image area. False otherwise.


def is_out_of_image(self, image, fully=True, partly=False):

if self.is_fully_within_image(image):<EOL><INDENT>return False<EOL><DEDENT>elif self.is_partly_within_image(image):<EOL><INDENT>return partly<EOL><DEDENT>else:<EOL><INDENT>return fully<EOL><DEDENT>

Estimate whether the bounding box is partially or fully outside of the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use. If an ndarray, its shape will be used. If a tuple, it is
    assumed to represent the image shape and must contain at least two integers.

fully : bool, optional
    Whether to return True if the bounding box is fully outside fo the image area.

partly : bool, optional
    Whether to return True if the bounding box is at least partially outside fo the
    image area.

Returns
-------
bool
    True if the bounding box is partially/fully outside of the image area, depending
    on defined parameters. False otherwise.


shape = normalize_shape(image)<EOL>height, width = shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>ia.do_assert(height > <NUM_LIT:0>)<EOL>ia.do_assert(width > <NUM_LIT:0>)<EOL>eps = np.finfo(np.float32).eps<EOL>x1 = np.clip(self.x1, <NUM_LIT:0>, width - eps)<EOL>x2 = np.clip(self.x2, <NUM_LIT:0>, width - eps)<EOL>y1 = np.clip(self.y1, <NUM_LIT:0>, height - eps)<EOL>y2 = np.clip(self.y2, <NUM_LIT:0>, height - eps)<EOL>return self.copy(<EOL>x1=x1,<EOL>y1=y1,<EOL>x2=x2,<EOL>y2=y2,<EOL>label=self.label<EOL>)<EOL>

Clip off all parts of the bounding box that are outside of the image.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use for the clipping of the bounding box.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape and must contain at least two integers.

Returns
-------
result : imgaug.BoundingBox
    Bounding box, clipped to fall within the image dimensions.


def shift(self, top=None, right=None, bottom=None, left=None):

top = top if top is not None else <NUM_LIT:0><EOL>right = right if right is not None else <NUM_LIT:0><EOL>bottom = bottom if bottom is not None else <NUM_LIT:0><EOL>left = left if left is not None else <NUM_LIT:0><EOL>return self.copy(<EOL>x1=self.x1+left-right,<EOL>x2=self.x2+left-right,<EOL>y1=self.y1+top-bottom,<EOL>y2=self.y2+top-bottom<EOL>)<EOL>

Shift the bounding box from one or more image sides, i.e. move it on the x/y-axis.

Parameters
----------
top : None or int, optional
    Amount of pixels by which to shift the bounding box from the top.

right : None or int, optional
    Amount of pixels by which to shift the bounding box from the right.

bottom : None or int, optional
    Amount of pixels by which to shift the bounding box from the bottom.

left : None or int, optional
    Amount of pixels by which to shift the bounding box from the left.

Returns
-------
result : imgaug.BoundingBox
    Shifted bounding box.


def draw_on_image(self, image, color=(<NUM_LIT:0>, <NUM_LIT:255>, <NUM_LIT:0>), alpha=<NUM_LIT:1.0>, size=<NUM_LIT:1>,<EOL>copy=True, raise_if_out_of_image=False, thickness=None):

if thickness is not None:<EOL><INDENT>ia.warn_deprecated(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>size = thickness<EOL><DEDENT>if raise_if_out_of_image and self.is_out_of_image(image):<EOL><INDENT>raise Exception("<STR_LIT>" % (<EOL>self.x1, self.y1, self.x2, self.y2, image.shape))<EOL><DEDENT>result = np.copy(image) if copy else image<EOL>if isinstance(color, (tuple, list)):<EOL><INDENT>color = np.uint8(color)<EOL><DEDENT>for i in range(size):<EOL><INDENT>y1, y2, x1, x2 = self.y1_int, self.y2_int, self.x1_int, self.x2_int<EOL>if self.is_fully_within_image(image):<EOL><INDENT>y1 = np.clip(y1, <NUM_LIT:0>, image.shape[<NUM_LIT:0>]-<NUM_LIT:1>)<EOL>y2 = np.clip(y2, <NUM_LIT:0>, image.shape[<NUM_LIT:0>]-<NUM_LIT:1>)<EOL>x1 = np.clip(x1, <NUM_LIT:0>, image.shape[<NUM_LIT:1>]-<NUM_LIT:1>)<EOL>x2 = np.clip(x2, <NUM_LIT:0>, image.shape[<NUM_LIT:1>]-<NUM_LIT:1>)<EOL><DEDENT>y = [y1-i, y1-i, y2+i, y2+i]<EOL>x = [x1-i, x2+i, x2+i, x1-i]<EOL>rr, cc = skimage.draw.polygon_perimeter(y, x, shape=result.shape)<EOL>if alpha >= <NUM_LIT>:<EOL><INDENT>result[rr, cc, :] = color<EOL><DEDENT>else:<EOL><INDENT>if ia.is_float_array(result):<EOL><INDENT>result[rr, cc, :] = (<NUM_LIT:1> - alpha) * result[rr, cc, :] + alpha * color<EOL>result = np.clip(result, <NUM_LIT:0>, <NUM_LIT:255>)<EOL><DEDENT>else:<EOL><INDENT>input_dtype = result.dtype<EOL>result = result.astype(np.float32)<EOL>result[rr, cc, :] = (<NUM_LIT:1> - alpha) * result[rr, cc, :] + alpha * color<EOL>result = np.clip(result, <NUM_LIT:0>, <NUM_LIT:255>).astype(input_dtype)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

Draw the bounding box on an image.

Parameters
----------
image : (H,W,C) ndarray(uint8)
    The image onto which to draw the bounding box.

color : iterable of int, optional
    The color to use, corresponding to the channel layout of the image. Usually RGB.

alpha : float, optional
    The transparency of the drawn bounding box, where 1.0 denotes no transparency and
    0.0 is invisible.

size : int, optional
    The thickness of the bounding box in pixels. If the value is larger than 1, then
    additional pixels will be added around the bounding box (i.e. extension towards the
    outside).

copy : bool, optional
    Whether to copy the input image or change it in-place.

raise_if_out_of_image : bool, optional
    Whether to raise an error if the bounding box is fully outside of the
    image. If set to False, no error will be raised and only the parts inside the image
    will be drawn.

thickness : None or int, optional
    Deprecated.

Returns
-------
result : (H,W,C) ndarray(uint8)
    Image with bounding box drawn on it.


def extract_from_image(self, image, pad=True, pad_max=None,<EOL>prevent_zero_size=True):

pad_top = <NUM_LIT:0><EOL>pad_right = <NUM_LIT:0><EOL>pad_bottom = <NUM_LIT:0><EOL>pad_left = <NUM_LIT:0><EOL>height, width = image.shape[<NUM_LIT:0>], image.shape[<NUM_LIT:1>]<EOL>x1, x2, y1, y2 = self.x1_int, self.x2_int, self.y1_int, self.y2_int<EOL>fully_within = self.is_fully_within_image(image)<EOL>if fully_within:<EOL><INDENT>y1, y2 = np.clip([y1, y2], <NUM_LIT:0>, height-<NUM_LIT:1>)<EOL>x1, x2 = np.clip([x1, x2], <NUM_LIT:0>, width-<NUM_LIT:1>)<EOL><DEDENT>if prevent_zero_size:<EOL><INDENT>if abs(x2 - x1) < <NUM_LIT:1>:<EOL><INDENT>x2 = x1 + <NUM_LIT:1><EOL><DEDENT>if abs(y2 - y1) < <NUM_LIT:1>:<EOL><INDENT>y2 = y1 + <NUM_LIT:1><EOL><DEDENT><DEDENT>if pad:<EOL><INDENT>if x1 < <NUM_LIT:0>:<EOL><INDENT>pad_left = abs(x1)<EOL>x2 = x2 + pad_left<EOL>width = width + pad_left<EOL>x1 = <NUM_LIT:0><EOL><DEDENT>if y1 < <NUM_LIT:0>:<EOL><INDENT>pad_top = abs(y1)<EOL>y2 = y2 + pad_top<EOL>height = height + pad_top<EOL>y1 = <NUM_LIT:0><EOL><DEDENT>if x2 >= width:<EOL><INDENT>pad_right = x2 - width<EOL><DEDENT>if y2 >= height:<EOL><INDENT>pad_bottom = y2 - height<EOL><DEDENT>paddings = [pad_top, pad_right, pad_bottom, pad_left]<EOL>any_padded = any([val > <NUM_LIT:0> for val in paddings])<EOL>if any_padded:<EOL><INDENT>if pad_max is None:<EOL><INDENT>pad_max = max(paddings)<EOL><DEDENT>image = ia.pad(<EOL>image,<EOL>top=min(pad_top, pad_max),<EOL>right=min(pad_right, pad_max),<EOL>bottom=min(pad_bottom, pad_max),<EOL>left=min(pad_left, pad_max)<EOL>)<EOL><DEDENT>return image[y1:y2, x1:x2]<EOL><DEDENT>else:<EOL><INDENT>within_image = (<EOL>(<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>)<EOL><= (x1, y1, x2, y2)<EOL>< (width, height, width, height)<EOL>)<EOL>out_height, out_width = (y2 - y1), (x2 - x1)<EOL>nonzero_height = (out_height > <NUM_LIT:0>)<EOL>nonzero_width = (out_width > <NUM_LIT:0>)<EOL>if within_image and nonzero_height and nonzero_width:<EOL><INDENT>return image[y1:y2, x1:x2]<EOL><DEDENT>if prevent_zero_size:<EOL><INDENT>out_height = <NUM_LIT:1><EOL>out_width = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>out_height = <NUM_LIT:0><EOL>out_width = <NUM_LIT:0><EOL><DEDENT>if image.ndim == <NUM_LIT:2>:<EOL><INDENT>return np.zeros((out_height, out_width), dtype=image.dtype)<EOL><DEDENT>return np.zeros((out_height, out_width, image.shape[-<NUM_LIT:1>]),<EOL>dtype=image.dtype)<EOL><DEDENT>

Extract the image pixels within the bounding box.

This function will zero-pad the image if the bounding box is partially/fully outside of
the image.

Parameters
----------
image : (H,W) ndarray or (H,W,C) ndarray
    The image from which to extract the pixels within the bounding box.

pad : bool, optional
    Whether to zero-pad the image if the object is partially/fully
    outside of it.

pad_max : None or int, optional
    The maximum number of pixels that may be zero-paded on any side,
    i.e. if this has value ``N`` the total maximum of added pixels
    is ``4*N``.
    This option exists to prevent extremely large images as a result of
    single points being moved very far away during augmentation.

prevent_zero_size : bool, optional
    Whether to prevent height or width of the extracted image from becoming zero.
    If this is set to True and height or width of the bounding box is below 1, the height/width will
    be increased to 1. This can be useful to prevent problems, e.g. with image saving or plotting.
    If it is set to False, images will be returned as ``(H', W')`` or ``(H', W', 3)`` with ``H`` or
    ``W`` potentially being 0.

Returns
-------
image : (H',W') ndarray or (H',W',C) ndarray
    Pixels within the bounding box. Zero-padded if the bounding box is partially/fully
    outside of the image. If prevent_zero_size is activated, it is guarantueed that ``H'>0``
    and ``W'>0``, otherwise only ``H'>=0`` and ``W'>=0``.


<EOL>from imgaug.augmentables.kps import Keypoint<EOL>return [<EOL>Keypoint(x=self.x1, y=self.y1),<EOL>Keypoint(x=self.x2, y=self.y1),<EOL>Keypoint(x=self.x2, y=self.y2),<EOL>Keypoint(x=self.x1, y=self.y2)<EOL>]<EOL>

Convert the corners of the bounding box to keypoints (clockwise, starting at top left).

Returns
-------
list of imgaug.Keypoint
    Corners of the bounding box as keypoints.


def copy(self, x1=None, y1=None, x2=None, y2=None, label=None):

return BoundingBox(<EOL>x1=self.x1 if x1 is None else x1,<EOL>x2=self.x2 if x2 is None else x2,<EOL>y1=self.y1 if y1 is None else y1,<EOL>y2=self.y2 if y2 is None else y2,<EOL>label=self.label if label is None else label<EOL>)<EOL>

Create a shallow copy of the BoundingBox object.

Parameters
----------
x1 : None or number
    If not None, then the x1 coordinate of the copied object will be set to this value.

y1 : None or number
    If not None, then the y1 coordinate of the copied object will be set to this value.

x2 : None or number
    If not None, then the x2 coordinate of the copied object will be set to this value.

y2 : None or number
    If not None, then the y2 coordinate of the copied object will be set to this value.

label : None or string
    If not None, then the label of the copied object will be set to this value.

Returns
-------
imgaug.BoundingBox
    Shallow copy.


def deepcopy(self, x1=None, y1=None, x2=None, y2=None, label=None):

return self.copy(x1=x1, y1=y1, x2=x2, y2=y2, label=label)<EOL>

Create a deep copy of the BoundingBox object.

Parameters
----------
x1 : None or number
    If not None, then the x1 coordinate of the copied object will be set to this value.

y1 : None or number
    If not None, then the y1 coordinate of the copied object will be set to this value.

x2 : None or number
    If not None, then the x2 coordinate of the copied object will be set to this value.

y2 : None or number
    If not None, then the y2 coordinate of the copied object will be set to this value.

label : None or string
    If not None, then the label of the copied object will be set to this value.

Returns
-------
imgaug.BoundingBox
    Deep copy.


return self.shape[<NUM_LIT:0>]<EOL>

Get the height of the image on which the bounding boxes fall.

Returns
-------
int
    Image height.


return self.shape[<NUM_LIT:1>]<EOL>

Get the width of the image on which the bounding boxes fall.

Returns
-------
int
    Image width.


return len(self.bounding_boxes) == <NUM_LIT:0><EOL>

Returns whether this object contains zero bounding boxes.

Returns
-------
bool
    True if this object contains zero bounding boxes.


shape = normalize_shape(image)<EOL>if shape[<NUM_LIT:0>:<NUM_LIT:2>] == self.shape[<NUM_LIT:0>:<NUM_LIT:2>]:<EOL><INDENT>return self.deepcopy()<EOL><DEDENT>bounding_boxes = [bb.project(self.shape, shape)<EOL>for bb in self.bounding_boxes]<EOL>return BoundingBoxesOnImage(bounding_boxes, shape)<EOL>

Project bounding boxes from one image to a new one.

Parameters
----------
image : ndarray or tuple of int
    New image onto which the bounding boxes are to be projected.
    May also simply be that new image's shape tuple.

Returns
-------
bounding_boxes : imgaug.BoundingBoxesOnImage
    Object containing all projected bounding boxes.


@classmethod<EOL><INDENT>def from_xyxy_array(cls, xyxy, shape):<DEDENT>

ia.do_assert(xyxy.shape[<NUM_LIT:1>] == <NUM_LIT:4>, "<STR_LIT>" % (xyxy.shape,))<EOL>boxes = [BoundingBox(*row) for row in xyxy]<EOL>return cls(boxes, shape)<EOL>

Convert an (N,4) ndarray to a BoundingBoxesOnImage object.

This is the inverse of :func:`imgaug.BoundingBoxesOnImage.to_xyxy_array`.

Parameters
----------
xyxy : (N,4) ndarray
    Array containing the corner coordinates (top-left, bottom-right) of ``N`` bounding boxes
    in the form ``(x1, y1, x2, y2)``. Should usually be of dtype ``float32``.

shape : tuple of int
    Shape of the image on which the bounding boxes are placed.
    Should usually be ``(H, W, C)`` or ``(H, W)``.

Returns
-------
imgaug.BoundingBoxesOnImage
    Object containing a list of BoundingBox objects following the provided corner coordinates.


xyxy_array = np.zeros((len(self.bounding_boxes), <NUM_LIT:4>), dtype=np.float32)<EOL>for i, box in enumerate(self.bounding_boxes):<EOL><INDENT>xyxy_array[i] = [box.x1, box.y1, box.x2, box.y2]<EOL><DEDENT>return xyxy_array.astype(dtype)<EOL>

Convert the BoundingBoxesOnImage object to an (N,4) ndarray.

This is the inverse of :func:`imgaug.BoundingBoxesOnImage.from_xyxy_array`.

Parameters
----------
dtype : numpy.dtype, optional
    Desired output datatype of the ndarray.

Returns
-------
ndarray
    (N,4) ndarray array, where ``N`` denotes the number of bounding boxes and ``4`` denotes the
    top-left and bottom-right bounding box corner coordinates in form ``(x1, y1, x2, y2)``.


image = np.copy(image) if copy else image<EOL>for bb in self.bounding_boxes:<EOL><INDENT>image = bb.draw_on_image(<EOL>image,<EOL>color=color,<EOL>alpha=alpha,<EOL>size=size,<EOL>copy=False,<EOL>raise_if_out_of_image=raise_if_out_of_image,<EOL>thickness=thickness<EOL>)<EOL><DEDENT>return image<EOL>

Draw all bounding boxes onto a given image.

Parameters
----------
image : (H,W,3) ndarray
    The image onto which to draw the bounding boxes.
    This image should usually have the same shape as
    set in BoundingBoxesOnImage.shape.

color : int or list of int or tuple of int or (3,) ndarray, optional
    The RGB color of all bounding boxes. If a single int ``C``, then
    that is equivalent to ``(C,C,C)``.

alpha : float, optional
    Alpha/transparency of the bounding box.

size : int, optional
    Thickness in pixels.

copy : bool, optional
    Whether to copy the image before drawing the bounding boxes.

raise_if_out_of_image : bool, optional
    Whether to raise an exception if any bounding box is outside of the
    image.

thickness : None or int, optional
    Deprecated.

Returns
-------
image : (H,W,3) ndarray
    Image with drawn bounding boxes.


def remove_out_of_image(self, fully=True, partly=False):

bbs_clean = [bb for bb in self.bounding_boxes<EOL>if not bb.is_out_of_image(self.shape, fully=fully, partly=partly)]<EOL>return BoundingBoxesOnImage(bbs_clean, shape=self.shape)<EOL>

Remove all bounding boxes that are fully or partially outside of the image.

Parameters
----------
fully : bool, optional
    Whether to remove bounding boxes that are fully outside of the image.

partly : bool, optional
    Whether to remove bounding boxes that are partially outside of the image.

Returns
-------
imgaug.BoundingBoxesOnImage
    Reduced set of bounding boxes, with those that were fully/partially outside of
    the image removed.


bbs_cut = [bb.clip_out_of_image(self.shape)<EOL>for bb in self.bounding_boxes if bb.is_partly_within_image(self.shape)]<EOL>return BoundingBoxesOnImage(bbs_cut, shape=self.shape)<EOL>

Clip off all parts from all bounding boxes that are outside of the image.

Returns
-------
imgaug.BoundingBoxesOnImage
    Bounding boxes, clipped to fall within the image dimensions.


bbs_new = [bb.shift(top=top, right=right, bottom=bottom, left=left) for bb in self.bounding_boxes]<EOL>return BoundingBoxesOnImage(bbs_new, shape=self.shape)<EOL>

Shift all bounding boxes from one or more image sides, i.e. move them on the x/y-axis.

Parameters
----------
top : None or int, optional
    Amount of pixels by which to shift all bounding boxes from the top.

right : None or int, optional
    Amount of pixels by which to shift all bounding boxes from the right.

bottom : None or int, optional
    Amount of pixels by which to shift all bounding boxes from the bottom.

left : None or int, optional
    Amount of pixels by which to shift all bounding boxes from the left.

Returns
-------
imgaug.BoundingBoxesOnImage
    Shifted bounding boxes.


return copy.copy(self)<EOL>

Create a shallow copy of the BoundingBoxesOnImage object.

Returns
-------
imgaug.BoundingBoxesOnImage
    Shallow copy.


<EOL>bbs = [bb.deepcopy() for bb in self.bounding_boxes]<EOL>return BoundingBoxesOnImage(bbs, tuple(self.shape))<EOL>

Create a deep copy of the BoundingBoxesOnImage object.

Returns
-------
imgaug.BoundingBoxesOnImage
    Deep copy.


assert all([<EOL>attr is None for attr_name, attr in self.__dict__.items()<EOL>if attr_name.endswith("<STR_LIT>")]),"<STR_LIT>""<STR_LIT>""<STR_LIT>"<EOL>images_unaug = nlib.normalize_images(self.images_unaug)<EOL>shapes = None<EOL>if images_unaug is not None:<EOL><INDENT>shapes = [image.shape for image in images_unaug]<EOL><DEDENT>return Batch(<EOL>images=images_unaug,<EOL>heatmaps=nlib.normalize_heatmaps(<EOL>self.heatmaps_unaug, shapes),<EOL>segmentation_maps=nlib.normalize_segmentation_maps(<EOL>self.segmentation_maps_unaug, shapes),<EOL>keypoints=nlib.normalize_keypoints(<EOL>self.keypoints_unaug, shapes),<EOL>bounding_boxes=nlib.normalize_bounding_boxes(<EOL>self.bounding_boxes_unaug, shapes),<EOL>polygons=nlib.normalize_polygons(<EOL>self.polygons_unaug, shapes),<EOL>line_strings=nlib.normalize_line_strings(<EOL>self.line_strings_unaug, shapes),<EOL>data=self.data<EOL>)<EOL>

Convert this unnormalized batch to an instance of Batch.

        As this method is intended to be called before augmentation, it
        assumes that none of the ``*_aug`` attributes is yet set.
        It will produce an AssertionError otherwise.

        The newly created Batch's ``*_unaug`` attributes will match the ones
        in this batch, just in normalized form.

        Returns
        -------
        imgaug.augmentables.batches.Batch
            The batch, with ``*_unaug`` attributes being normalized.


<EOL>batch = UnnormalizedBatch(<EOL>images=self.images_unaug,<EOL>heatmaps=self.heatmaps_unaug,<EOL>segmentation_maps=self.segmentation_maps_unaug,<EOL>keypoints=self.keypoints_unaug,<EOL>bounding_boxes=self.bounding_boxes_unaug,<EOL>polygons=self.polygons_unaug,<EOL>line_strings=self.line_strings_unaug,<EOL>data=batch_aug_norm.data<EOL>)<EOL>batch.images_aug = nlib.invert_normalize_images(<EOL>batch_aug_norm.images_aug, self.images_unaug)<EOL>batch.heatmaps_aug = nlib.invert_normalize_heatmaps(<EOL>batch_aug_norm.heatmaps_aug, self.heatmaps_unaug)<EOL>batch.segmentation_maps_aug = nlib.invert_normalize_segmentation_maps(<EOL>batch_aug_norm.segmentation_maps_aug, self.segmentation_maps_unaug)<EOL>batch.keypoints_aug = nlib.invert_normalize_keypoints(<EOL>batch_aug_norm.keypoints_aug, self.keypoints_unaug)<EOL>batch.bounding_boxes_aug = nlib.invert_normalize_bounding_boxes(<EOL>batch_aug_norm.bounding_boxes_aug, self.bounding_boxes_unaug)<EOL>batch.polygons_aug = nlib.invert_normalize_polygons(<EOL>batch_aug_norm.polygons_aug, self.polygons_unaug)<EOL>batch.line_strings_aug = nlib.invert_normalize_line_strings(<EOL>batch_aug_norm.line_strings_aug, self.line_strings_unaug)<EOL>return batch<EOL>

Fill this batch with (normalized) augmentation results.

This method receives a (normalized) Batch instance, takes all
``*_aug`` attributes out if it and assigns them to this
batch *in unnormalized form*. Hence, the datatypes of all ``*_aug``
attributes will match the datatypes of the ``*_unaug`` attributes.

Parameters
----------
batch_aug_norm: imgaug.augmentables.batches.Batch
    Batch after normalization and augmentation.

Returns
-------
imgaug.augmentables.batches.UnnormalizedBatch
    New UnnormalizedBatch instance. All ``*_unaug`` attributes are
    taken from the old UnnormalizedBatch (without deepcopying them)
    and all ``*_aug`` attributes are taken from `batch_normalized`
    converted to unnormalized form.


def __init__(self, arr, shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>):

ia.do_assert(ia.is_np_array(arr), "<STR_LIT>" % (type(arr),))<EOL>ia.do_assert(arr.shape[<NUM_LIT:0>] > <NUM_LIT:0> and arr.shape[<NUM_LIT:1>] > <NUM_LIT:0>,<EOL>"<STR_LIT>" % (<EOL>arr.shape,))<EOL>ia.do_assert(arr.dtype.type in [np.float32],<EOL>"<STR_LIT>" % (arr.dtype,))<EOL>ia.do_assert(arr.ndim in [<NUM_LIT:2>, <NUM_LIT:3>], "<STR_LIT>" % (arr.shape,))<EOL>ia.do_assert(len(shape) in [<NUM_LIT:2>, <NUM_LIT:3>],<EOL>"<STR_LIT>" % (shape,))<EOL>ia.do_assert(min_value < max_value)<EOL>if np.min(arr.flat[<NUM_LIT:0>:<NUM_LIT:50>]) < min_value - np.finfo(arr.dtype).epsor np.max(arr.flat[<NUM_LIT:0>:<NUM_LIT:50>]) > max_value + np.finfo(arr.dtype).eps:<EOL><INDENT>import warnings<EOL>warnings.warn(<EOL>("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>min_value, max_value, np.min(arr), np.max(arr)))<EOL>arr = np.clip(arr, min_value, max_value)<EOL><DEDENT>if arr.ndim == <NUM_LIT:2>:<EOL><INDENT>arr = arr[..., np.newaxis]<EOL>self.arr_was_2d = True<EOL><DEDENT>else:<EOL><INDENT>self.arr_was_2d = False<EOL><DEDENT>eps = np.finfo(np.float32).eps<EOL>min_is_zero = <NUM_LIT:0.0> - eps < min_value < <NUM_LIT:0.0> + eps<EOL>max_is_one = <NUM_LIT:1.0> - eps < max_value < <NUM_LIT:1.0> + eps<EOL>if min_is_zero and max_is_one:<EOL><INDENT>self.arr_0to1 = arr<EOL><DEDENT>else:<EOL><INDENT>self.arr_0to1 = (arr - min_value) / (max_value - min_value)<EOL><DEDENT>self.shape = shape<EOL>self.min_value = min_value<EOL>self.max_value = max_value<EOL>


if self.arr_was_2d and self.arr_0to1.shape[<NUM_LIT:2>] == <NUM_LIT:1>:<EOL><INDENT>arr = self.arr_0to1[:, :, <NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>arr = self.arr_0to1<EOL><DEDENT>eps = np.finfo(np.float32).eps<EOL>min_is_zero = <NUM_LIT:0.0> - eps < self.min_value < <NUM_LIT:0.0> + eps<EOL>max_is_one = <NUM_LIT:1.0> - eps < self.max_value < <NUM_LIT:1.0> + eps<EOL>if min_is_zero and max_is_one:<EOL><INDENT>return np.copy(arr)<EOL><DEDENT>else:<EOL><INDENT>diff = self.max_value - self.min_value<EOL>return self.min_value + diff * arr<EOL><DEDENT>

Get the heatmap's array within the value range originally provided in ``__init__()``.

The HeatmapsOnImage object saves heatmaps internally in the value range ``(min=0.0, max=1.0)``.
This function converts the internal representation to ``(min=min_value, max=max_value)``,
where ``min_value`` and ``max_value`` are provided upon instantiation of the object.

Returns
-------
result : (H,W) ndarray or (H,W,C) ndarray
    Heatmap array. Dtype is float32.


def draw(self, size=None, cmap="<STR_LIT>"):

heatmaps_uint8 = self.to_uint8()<EOL>heatmaps_drawn = []<EOL>for c in sm.xrange(heatmaps_uint8.shape[<NUM_LIT:2>]):<EOL><INDENT>heatmap_c = heatmaps_uint8[..., c:c+<NUM_LIT:1>]<EOL>if size is not None:<EOL><INDENT>heatmap_c_rs = ia.imresize_single_image(heatmap_c, size, interpolation="<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>heatmap_c_rs = heatmap_c<EOL><DEDENT>heatmap_c_rs = np.squeeze(heatmap_c_rs).astype(np.float32) / <NUM_LIT><EOL>if cmap is not None:<EOL><INDENT>import matplotlib.pyplot as plt<EOL>cmap_func = plt.get_cmap(cmap)<EOL>heatmap_cmapped = cmap_func(heatmap_c_rs)<EOL>heatmap_cmapped = np.delete(heatmap_cmapped, <NUM_LIT:3>, <NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>heatmap_cmapped = np.tile(heatmap_c_rs[..., np.newaxis], (<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:3>))<EOL><DEDENT>heatmap_cmapped = np.clip(heatmap_cmapped * <NUM_LIT:255>, <NUM_LIT:0>, <NUM_LIT:255>).astype(np.uint8)<EOL>heatmaps_drawn.append(heatmap_cmapped)<EOL><DEDENT>return heatmaps_drawn<EOL>

Render the heatmaps as RGB images.

Parameters
----------
size : None or float or iterable of int or iterable of float, optional
    Size of the rendered RGB image as ``(height, width)``.
    See :func:`imgaug.imgaug.imresize_single_image` for details.
    If set to None, no resizing is performed and the size of the heatmaps array is used.

cmap : str or None, optional
    Color map of ``matplotlib`` to use in order to convert the heatmaps to RGB images.
    If set to None, no color map will be used and the heatmaps will be converted
    to simple intensity maps.

Returns
-------
heatmaps_drawn : list of (H,W,3) ndarray
    Rendered heatmaps. One per heatmap array channel. Dtype is uint8.


def draw_on_image(self, image, alpha=<NUM_LIT>, cmap="<STR_LIT>", resize="<STR_LIT>"):

<EOL>ia.do_assert(image.ndim == <NUM_LIT:3>)<EOL>ia.do_assert(image.shape[<NUM_LIT:2>] == <NUM_LIT:3>)<EOL>ia.do_assert(image.dtype.type == np.uint8)<EOL>ia.do_assert(<NUM_LIT:0> - <NUM_LIT> <= alpha <= <NUM_LIT:1.0> + <NUM_LIT>)<EOL>ia.do_assert(resize in ["<STR_LIT>", "<STR_LIT:image>"])<EOL>if resize == "<STR_LIT:image>":<EOL><INDENT>image = ia.imresize_single_image(image, self.arr_0to1.shape[<NUM_LIT:0>:<NUM_LIT:2>], interpolation="<STR_LIT>")<EOL><DEDENT>heatmaps_drawn = self.draw(<EOL>size=image.shape[<NUM_LIT:0>:<NUM_LIT:2>] if resize == "<STR_LIT>" else None,<EOL>cmap=cmap<EOL>)<EOL>mix = [<EOL>np.clip((<NUM_LIT:1>-alpha) * image + alpha * heatmap_i, <NUM_LIT:0>, <NUM_LIT:255>).astype(np.uint8)<EOL>for heatmap_i<EOL>in heatmaps_drawn<EOL>]<EOL>return mix<EOL>

Draw the heatmaps as overlays over an image.

Parameters
----------
image : (H,W,3) ndarray
    Image onto which to draw the heatmaps. Expected to be of dtype uint8.

alpha : float, optional
    Alpha/opacity value to use for the mixing of image and heatmaps.
    Higher values mean that the heatmaps will be more visible and the image less visible.

cmap : str or None, optional
    Color map to use. See :func:`imgaug.HeatmapsOnImage.draw` for details.

resize : {'heatmaps', 'image'}, optional
    In case of size differences between the image and heatmaps, either the image or
    the heatmaps can be resized. This parameter controls which of the two will be resized
    to the other's size.

Returns
-------
mix : list of (H,W,3) ndarray
    Rendered overlays. One per heatmap array channel. Dtype is uint8.


arr_inv = HeatmapsOnImage.from_0to1(<NUM_LIT:1> - self.arr_0to1, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>arr_inv.arr_was_2d = self.arr_was_2d<EOL>return arr_inv<EOL>

Inverts each value in the heatmap, shifting low towards high values and vice versa.

This changes each value to::

    v' = max - (v - min)

where ``v`` is the value at some spatial location, ``min`` is the minimum value in the heatmap
and ``max`` is the maximum value.
As the heatmap uses internally a 0.0 to 1.0 representation, this simply becomes ``v' = 1.0 - v``.

Note that the attributes ``min_value`` and ``max_value`` are not switched. They both keep their values.

This function can be useful e.g. when working with depth maps, where algorithms might have
an easier time representing the furthest away points with zeros, requiring an inverted
depth map.

Returns
-------
arr_inv : imgaug.HeatmapsOnImage
    Inverted heatmap.


def pad(self, top=<NUM_LIT:0>, right=<NUM_LIT:0>, bottom=<NUM_LIT:0>, left=<NUM_LIT:0>, mode="<STR_LIT>", cval=<NUM_LIT:0.0>):

arr_0to1_padded = ia.pad(self.arr_0to1, top=top, right=right, bottom=bottom, left=left, mode=mode, cval=cval)<EOL>return HeatmapsOnImage.from_0to1(arr_0to1_padded, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>

Pad the heatmaps on their top/right/bottom/left side.

Parameters
----------
top : int, optional
    Amount of pixels to add at the top side of the heatmaps. Must be 0 or greater.

right : int, optional
    Amount of pixels to add at the right side of the heatmaps. Must be 0 or greater.

bottom : int, optional
    Amount of pixels to add at the bottom side of the heatmaps. Must be 0 or greater.

left : int, optional
    Amount of pixels to add at the left side of the heatmaps. Must be 0 or greater.

mode : string, optional
    Padding mode to use. See :func:`numpy.pad` for details.

cval : number, optional
    Value to use for padding if `mode` is ``constant``. See :func:`numpy.pad` for details.

Returns
-------
imgaug.HeatmapsOnImage
    Padded heatmaps of height ``H'=H+top+bottom`` and width ``W'=W+left+right``.


def pad_to_aspect_ratio(self, aspect_ratio, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, return_pad_amounts=False):

arr_0to1_padded, pad_amounts = ia.pad_to_aspect_ratio(self.arr_0to1, aspect_ratio=aspect_ratio, mode=mode,<EOL>cval=cval, return_pad_amounts=True)<EOL>heatmaps = HeatmapsOnImage.from_0to1(arr_0to1_padded, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>if return_pad_amounts:<EOL><INDENT>return heatmaps, pad_amounts<EOL><DEDENT>else:<EOL><INDENT>return heatmaps<EOL><DEDENT>

Pad the heatmaps on their sides so that they match a target aspect ratio.

Depending on which dimension is smaller (height or width), only the corresponding
sides (left/right or top/bottom) will be padded. In each case, both of the sides will
be padded equally.

Parameters
----------
aspect_ratio : float
    Target aspect ratio, given as width/height. E.g. 2.0 denotes the image having twice
    as much width as height.

mode : str, optional
    Padding mode to use. See :func:`numpy.pad` for details.

cval : number, optional
    Value to use for padding if `mode` is ``constant``. See :func:`numpy.pad` for details.

return_pad_amounts : bool, optional
    If False, then only the padded image will be returned. If True, a tuple with two
    entries will be returned, where the first entry is the padded image and the second
    entry are the amounts by which each image side was padded. These amounts are again a
    tuple of the form (top, right, bottom, left), with each value being an integer.

Returns
-------
heatmaps : imgaug.HeatmapsOnImage
    Padded heatmaps as HeatmapsOnImage object.

pad_amounts : tuple of int
    Amounts by which the heatmaps were padded on each side, given as a tuple ``(top, right, bottom, left)``.
    This tuple is only returned if `return_pad_amounts` was set to True.


arr_0to1_reduced = ia.avg_pool(self.arr_0to1, block_size, cval=<NUM_LIT:0.0>)<EOL>return HeatmapsOnImage.from_0to1(arr_0to1_reduced, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>

Resize the heatmap(s) array using average pooling of a given block/kernel size.

Parameters
----------
block_size : int or tuple of int
    Size of each block of values to pool, aka kernel size. See :func:`imgaug.pool` for details.

Returns
-------
imgaug.HeatmapsOnImage
    Heatmaps after average pooling.


arr_0to1_reduced = ia.max_pool(self.arr_0to1, block_size)<EOL>return HeatmapsOnImage.from_0to1(arr_0to1_reduced, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>

Resize the heatmap(s) array using max-pooling of a given block/kernel size.

Parameters
----------
block_size : int or tuple of int
    Size of each block of values to pool, aka kernel size. See :func:`imgaug.pool` for details.

Returns
-------
imgaug.HeatmapsOnImage
    Heatmaps after max-pooling.


def resize(self, sizes, interpolation="<STR_LIT>"):

arr_0to1_resized = ia.imresize_single_image(self.arr_0to1, sizes, interpolation=interpolation)<EOL>arr_0to1_resized = np.clip(arr_0to1_resized, <NUM_LIT:0.0>, <NUM_LIT:1.0>)<EOL>return HeatmapsOnImage.from_0to1(arr_0to1_resized, shape=self.shape, min_value=self.min_value,<EOL>max_value=self.max_value)<EOL>

Resize the heatmap(s) array to the provided size given the provided interpolation.

Parameters
----------
sizes : float or iterable of int or iterable of float
    New size of the array in ``(height, width)``.
    See :func:`imgaug.imgaug.imresize_single_image` for details.

interpolation : None or str or int, optional
    The interpolation to use during resize.
    See :func:`imgaug.imgaug.imresize_single_image` for details.

Returns
-------
imgaug.HeatmapsOnImage
    Resized heatmaps object.


<EOL>arr_0to255 = np.clip(np.round(self.arr_0to1 * <NUM_LIT:255>), <NUM_LIT:0>, <NUM_LIT:255>)<EOL>arr_uint8 = arr_0to255.astype(np.uint8)<EOL>return arr_uint8<EOL>

Convert this heatmaps object to a 0-to-255 array.

Returns
-------
arr_uint8 : (H,W,C) ndarray
    Heatmap as a 0-to-255 array (dtype is uint8).


@staticmethod<EOL><INDENT>def from_uint8(arr_uint8, shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>):<DEDENT>

arr_0to1 = arr_uint8.astype(np.float32) / <NUM_LIT><EOL>return HeatmapsOnImage.from_0to1(arr_0to1, shape, min_value=min_value, max_value=max_value)<EOL>

Create a heatmaps object from an heatmap array containing values ranging from 0 to 255.

Parameters
----------
arr_uint8 : (H,W) ndarray or (H,W,C) ndarray
    Heatmap(s) array, where ``H`` is height, ``W`` is width and ``C`` is the number of heatmap channels.
    Expected dtype is uint8.

shape : tuple of int
    Shape of the image on which the heatmap(s) is/are placed. NOT the shape of the
    heatmap(s) array, unless it is identical to the image shape (note the likely
    difference between the arrays in the number of channels).
    If there is not a corresponding image, use the shape of the heatmaps array.

min_value : float, optional
    Minimum value for the heatmaps that the 0-to-255 array represents. This will usually
    be 0.0. It is used when calling :func:`imgaug.HeatmapsOnImage.get_arr`, which converts the
    underlying ``(0, 255)`` array to value range ``(min_value, max_value)``.

max_value : float, optional
    Maximum value for the heatmaps that 0-to-255 array represents.
    See parameter `min_value` for details.

Returns
-------
imgaug.HeatmapsOnImage
    Heatmaps object.


@staticmethod<EOL><INDENT>def from_0to1(arr_0to1, shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>):<DEDENT>

heatmaps = HeatmapsOnImage(arr_0to1, shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>)<EOL>heatmaps.min_value = min_value<EOL>heatmaps.max_value = max_value<EOL>return heatmaps<EOL>

Create a heatmaps object from an heatmap array containing values ranging from 0.0 to 1.0.

Parameters
----------
arr_0to1 : (H,W) or (H,W,C) ndarray
    Heatmap(s) array, where ``H`` is height, ``W`` is width and ``C`` is the number of heatmap channels.
    Expected dtype is float32.

shape : tuple of ints
    Shape of the image on which the heatmap(s) is/are placed. NOT the shape of the
    heatmap(s) array, unless it is identical to the image shape (note the likely
    difference between the arrays in the number of channels).
    If there is not a corresponding image, use the shape of the heatmaps array.

min_value : float, optional
    Minimum value for the heatmaps that the 0-to-1 array represents. This will usually
    be 0.0. It is used when calling :func:`imgaug.HeatmapsOnImage.get_arr`, which converts the
    underlying ``(0.0, 1.0)`` array to value range ``(min_value, max_value)``.
    E.g. if you started with heatmaps in the range ``(-1.0, 1.0)`` and projected these
    to (0.0, 1.0), you should call this function with ``min_value=-1.0``, ``max_value=1.0``
    so that :func:`imgaug.HeatmapsOnImage.get_arr` returns heatmap arrays having value
    range (-1.0, 1.0).

max_value : float, optional
    Maximum value for the heatmaps that to 0-to-255 array represents.
    See parameter min_value for details.

Returns
-------
heatmaps : imgaug.HeatmapsOnImage
    Heatmaps object.


@classmethod<EOL><INDENT>def change_normalization(cls, arr, source, target):<DEDENT>

ia.do_assert(ia.is_np_array(arr))<EOL>if isinstance(source, HeatmapsOnImage):<EOL><INDENT>source = (source.min_value, source.max_value)<EOL><DEDENT>else:<EOL><INDENT>ia.do_assert(isinstance(source, tuple))<EOL>ia.do_assert(len(source) == <NUM_LIT:2>)<EOL>ia.do_assert(source[<NUM_LIT:0>] < source[<NUM_LIT:1>])<EOL><DEDENT>if isinstance(target, HeatmapsOnImage):<EOL><INDENT>target = (target.min_value, target.max_value)<EOL><DEDENT>else:<EOL><INDENT>ia.do_assert(isinstance(target, tuple))<EOL>ia.do_assert(len(target) == <NUM_LIT:2>)<EOL>ia.do_assert(target[<NUM_LIT:0>] < target[<NUM_LIT:1>])<EOL><DEDENT>eps = np.finfo(arr.dtype).eps<EOL>mins_same = source[<NUM_LIT:0>] - <NUM_LIT:10>*eps < target[<NUM_LIT:0>] < source[<NUM_LIT:0>] + <NUM_LIT:10>*eps<EOL>maxs_same = source[<NUM_LIT:1>] - <NUM_LIT:10>*eps < target[<NUM_LIT:1>] < source[<NUM_LIT:1>] + <NUM_LIT:10>*eps<EOL>if mins_same and maxs_same:<EOL><INDENT>return np.copy(arr)<EOL><DEDENT>min_source, max_source = source<EOL>min_target, max_target = target<EOL>diff_source = max_source - min_source<EOL>diff_target = max_target - min_target<EOL>arr_0to1 = (arr - min_source) / diff_source<EOL>arr_target = min_target + arr_0to1 * diff_target<EOL>return arr_target<EOL>

Change the value range of a heatmap from one min-max to another min-max.

E.g. the value range may be changed from min=0.0, max=1.0 to min=-1.0, max=1.0.

Parameters
----------
arr : ndarray
    Heatmap array to modify.

source : tuple of float
    Current value range of the input array, given as (min, max), where both are float values.

target : tuple of float
    Desired output value range of the array, given as (min, max), where both are float values.

Returns
-------
arr_target : ndarray
    Input array, with value range projected to the desired target value range.


return self.deepcopy()<EOL>

Create a shallow copy of the Heatmaps object.

Returns
-------
imgaug.HeatmapsOnImage
    Shallow copy.


return HeatmapsOnImage(self.get_arr(), shape=self.shape, min_value=self.min_value, max_value=self.max_value)<EOL>

Create a deep copy of the Heatmaps object.

Returns
-------
imgaug.HeatmapsOnImage
    Deep copy.


def __init__(self, exterior, label=None):

<EOL>from imgaug.augmentables.kps import Keypoint<EOL>if isinstance(exterior, list):<EOL><INDENT>if not exterior:<EOL><INDENT>self.exterior = np.zeros((<NUM_LIT:0>, <NUM_LIT:2>), dtype=np.float32)<EOL><DEDENT>elif isinstance(exterior[<NUM_LIT:0>], Keypoint):<EOL><INDENT>self.exterior = np.float32([[point.x, point.y] for point in exterior])<EOL><DEDENT>else:<EOL><INDENT>self.exterior = np.float32([[point[<NUM_LIT:0>], point[<NUM_LIT:1>]] for point in exterior])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ia.do_assert(ia.is_np_array(exterior),<EOL>("<STR_LIT>"<EOL>+ "<STR_LIT>") % (exterior,))<EOL>ia.do_assert(exterior.ndim == <NUM_LIT:2> and exterior.shape[<NUM_LIT:1>] == <NUM_LIT:2>,<EOL>("<STR_LIT>"<EOL>+ "<STR_LIT>") % (<EOL>exterior.shape,))<EOL>self.exterior = np.float32(exterior)<EOL><DEDENT>if len(self.exterior) >= <NUM_LIT:2> and np.allclose(self.exterior[<NUM_LIT:0>, :], self.exterior[-<NUM_LIT:1>, :]):<EOL><INDENT>self.exterior = self.exterior[:-<NUM_LIT:1>]<EOL><DEDENT>self.label = label<EOL>


return self.exterior[:, <NUM_LIT:0>]<EOL>

Return the x-coordinates of all points in the exterior.

Returns
-------
(N,2) ndarray
    X-coordinates of all points in the exterior as a float32 ndarray.


return self.exterior[:, <NUM_LIT:1>]<EOL>

Return the y-coordinates of all points in the exterior.

Returns
-------
(N,2) ndarray
    Y-coordinates of all points in the exterior as a float32 ndarray.


return np.int32(np.round(self.xx))<EOL>

Return the x-coordinates of all points in the exterior, rounded to the closest integer value.

Returns
-------
(N,2) ndarray
    X-coordinates of all points in the exterior, rounded to the closest integer value.
    Result dtype is int32.


return np.int32(np.round(self.yy))<EOL>

Return the y-coordinates of all points in the exterior, rounded to the closest integer value.

Returns
-------
(N,2) ndarray
    Y-coordinates of all points in the exterior, rounded to the closest integer value.
    Result dtype is int32.


if len(self.exterior) < <NUM_LIT:3>:<EOL><INDENT>return False<EOL><DEDENT>return self.to_shapely_polygon().is_valid<EOL>

Estimate whether the polygon has a valid shape.

To to be considered valid, the polygons must be made up of at least 3 points and have concave shape.
Multiple consecutive points are allowed to have the same coordinates.

Returns
-------
bool
    True if polygon has at least 3 points and is concave, otherwise False.


if len(self.exterior) < <NUM_LIT:3>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>poly = self.to_shapely_polygon()<EOL>return poly.area<EOL>

Estimate the area of the polygon.

Returns
-------
number
    Area of the polygon.


yy = self.yy<EOL>return max(yy) - min(yy)<EOL>

Estimate the height of the polygon.

Returns
-------
number
    Height of the polygon.


xx = self.xx<EOL>return max(xx) - min(xx)<EOL>

Estimate the width of the polygon.

Returns
-------
number
    Width of the polygon.


def project(self, from_shape, to_shape):

if from_shape[<NUM_LIT:0>:<NUM_LIT:2>] == to_shape[<NUM_LIT:0>:<NUM_LIT:2>]:<EOL><INDENT>return self.copy()<EOL><DEDENT>ls_proj = self.to_line_string(closed=False).project(<EOL>from_shape, to_shape)<EOL>return self.copy(exterior=ls_proj.coords)<EOL>

Project the polygon onto an image with different shape.

The relative coordinates of all points remain the same.
E.g. a point at (x=20, y=20) on an image (width=100, height=200) will be
projected on a new image (width=200, height=100) to (x=40, y=10).

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
-------
imgaug.Polygon
    Polygon object with new coordinates.


def find_closest_point_index(self, x, y, return_distance=False):

ia.do_assert(len(self.exterior) > <NUM_LIT:0>)<EOL>distances = []<EOL>for x2, y2 in self.exterior:<EOL><INDENT>d = (x2 - x) ** <NUM_LIT:2> + (y2 - y) ** <NUM_LIT:2><EOL>distances.append(d)<EOL><DEDENT>distances = np.sqrt(distances)<EOL>closest_idx = np.argmin(distances)<EOL>if return_distance:<EOL><INDENT>return closest_idx, distances[closest_idx]<EOL><DEDENT>return closest_idx<EOL>

Find the index of the point within the exterior that is closest to the given coordinates.

"Closeness" is here defined based on euclidean distance.
This method will raise an AssertionError if the exterior contains no points.

Parameters
----------
x : number
    X-coordinate around which to search for close points.

y : number
    Y-coordinate around which to search for close points.

return_distance : bool, optional
    Whether to also return the distance of the closest point.

Returns
-------
int
    Index of the closest point.

number
    Euclidean distance to the closest point.
    This value is only returned if `return_distance` was set to True.


return not self.is_out_of_image(image, fully=True, partly=True)<EOL>

Estimate whether the polygon is fully inside the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape and must contain at least two integers.

Returns
-------
bool
    True if the polygon is fully inside the image area.
    False otherwise.


return not self.is_out_of_image(image, fully=True, partly=False)<EOL>

Estimate whether the polygon is at least partially inside the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape and must contain at least two integers.

Returns
-------
bool
    True if the polygon is at least partially inside the image area.
    False otherwise.


def is_out_of_image(self, image, fully=True, partly=False):

<EOL>if len(self.exterior) == <NUM_LIT:0>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>ls = self.to_line_string()<EOL>return ls.is_out_of_image(image, fully=fully, partly=partly)<EOL>

Estimate whether the polygon is partially or fully outside of the image area.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape and must contain at least two integers.

fully : bool, optional
    Whether to return True if the polygon is fully outside of the image area.

partly : bool, optional
    Whether to return True if the polygon is at least partially outside fo the image area.

Returns
-------
bool
    True if the polygon is partially/fully outside of the image area, depending
    on defined parameters. False otherwise.


<EOL>import shapely.geometry<EOL>if self.is_out_of_image(image, fully=True, partly=False):<EOL><INDENT>return []<EOL><DEDENT>h, w = image.shape[<NUM_LIT:0>:<NUM_LIT:2>] if ia.is_np_array(image) else image[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>poly_shapely = self.to_shapely_polygon()<EOL>poly_image = shapely.geometry.Polygon([(<NUM_LIT:0>, <NUM_LIT:0>), (w, <NUM_LIT:0>), (w, h), (<NUM_LIT:0>, h)])<EOL>multipoly_inter_shapely = poly_shapely.intersection(poly_image)<EOL>if not isinstance(multipoly_inter_shapely, shapely.geometry.MultiPolygon):<EOL><INDENT>ia.do_assert(isinstance(multipoly_inter_shapely, shapely.geometry.Polygon))<EOL>multipoly_inter_shapely = shapely.geometry.MultiPolygon([multipoly_inter_shapely])<EOL><DEDENT>polygons = []<EOL>for poly_inter_shapely in multipoly_inter_shapely.geoms:<EOL><INDENT>polygons.append(Polygon.from_shapely(poly_inter_shapely, label=self.label))<EOL><DEDENT>polygons_reordered = []<EOL>for polygon in polygons:<EOL><INDENT>found = False<EOL>for x, y in self.exterior:<EOL><INDENT>closest_idx, dist = polygon.find_closest_point_index(x=x, y=y, return_distance=True)<EOL>if dist < <NUM_LIT>:<EOL><INDENT>polygon_reordered = polygon.change_first_point_by_index(closest_idx)<EOL>polygons_reordered.append(polygon_reordered)<EOL>found = True<EOL>break<EOL><DEDENT><DEDENT>ia.do_assert(found)  <EOL><DEDENT>return polygons_reordered<EOL>

Cut off all parts of the polygon that are outside of the image.

This operation may lead to new points being created.
As a single polygon may be split into multiple new polygons, the result
is always a list, which may contain more than one output polygon.

This operation will return an empty list if the polygon is completely
outside of the image plane.

Parameters
----------
image : (H,W,...) ndarray or tuple of int
    Image dimensions to use for the clipping of the polygon.
    If an ndarray, its shape will be used.
    If a tuple, it is assumed to represent the image shape and must
    contain at least two integers.

Returns
-------
list of imgaug.Polygon
    Polygon, clipped to fall within the image dimensions.
    Returned as a list, because the clipping can split the polygon into
    multiple parts. The list may also be empty, if the polygon was
    fully outside of the image plane.


def shift(self, top=None, right=None, bottom=None, left=None):

ls_shifted = self.to_line_string(closed=False).shift(<EOL>top=top, right=right, bottom=bottom, left=left)<EOL>return self.copy(exterior=ls_shifted.coords)<EOL>

Shift the polygon from one or more image sides, i.e. move it on the x/y-axis.

Parameters
----------
top : None or int, optional
    Amount of pixels by which to shift the polygon from the top.

right : None or int, optional
    Amount of pixels by which to shift the polygon from the right.

bottom : None or int, optional
    Amount of pixels by which to shift the polygon from the bottom.

left : None or int, optional
    Amount of pixels by which to shift the polygon from the left.

Returns
-------
imgaug.Polygon
    Shifted polygon.


def draw_on_image(self,<EOL>image,<EOL>color=(<NUM_LIT:0>, <NUM_LIT:255>, <NUM_LIT:0>), color_face=None,<EOL>color_lines=None, color_points=None,<EOL>alpha=<NUM_LIT:1.0>, alpha_face=None,<EOL>alpha_lines=None, alpha_points=None,<EOL>size=<NUM_LIT:1>, size_lines=None, size_points=None,<EOL>raise_if_out_of_image=False):

assert color is not None<EOL>assert alpha is not None<EOL>assert size is not None<EOL>color_face = color_face if color_face is not None else np.array(color)<EOL>color_lines = color_lines if color_lines is not None else np.array(color) * <NUM_LIT:0.5><EOL>color_points = color_points if color_points is not None else np.array(color) * <NUM_LIT:0.5><EOL>alpha_face = alpha_face if alpha_face is not None else alpha * <NUM_LIT:0.5><EOL>alpha_lines = alpha_lines if alpha_lines is not None else alpha<EOL>alpha_points = alpha_points if alpha_points is not None else alpha<EOL>size_lines = size_lines if size_lines is not None else size<EOL>size_points = size_points if size_points is not None else size * <NUM_LIT:3><EOL>if image.ndim == <NUM_LIT:2>:<EOL><INDENT>assert ia.is_single_number(color_face), (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (str(color_face),))<EOL>color_face = [color_face]<EOL><DEDENT>elif image.ndim == <NUM_LIT:3> and ia.is_single_number(color_face):<EOL><INDENT>color_face = [color_face] * image.shape[-<NUM_LIT:1>]<EOL><DEDENT>if alpha_face < <NUM_LIT>:<EOL><INDENT>alpha_face = <NUM_LIT:0><EOL><DEDENT>elif alpha_face > <NUM_LIT>:<EOL><INDENT>alpha_face = <NUM_LIT:1><EOL><DEDENT>if raise_if_out_of_image and self.is_out_of_image(image):<EOL><INDENT>raise Exception("<STR_LIT>" % (<EOL>str(self), image.shape<EOL>))<EOL><DEDENT>input_dtype = image.dtype<EOL>result = image.astype(np.float32)<EOL>rr, cc = skimage.draw.polygon(self.yy_int, self.xx_int, shape=image.shape)<EOL>if len(rr) > <NUM_LIT:0>:<EOL><INDENT>if alpha_face == <NUM_LIT:1>:<EOL><INDENT>result[rr, cc] = np.float32(color_face)<EOL><DEDENT>elif alpha_face == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>result[rr, cc] = (<EOL>(<NUM_LIT:1> - alpha_face) * result[rr, cc, :]<EOL>+ alpha_face * np.float32(color_face)<EOL>)<EOL><DEDENT><DEDENT>ls_open = self.to_line_string(closed=False)<EOL>ls_closed = self.to_line_string(closed=True)<EOL>result = ls_closed.draw_lines_on_image(<EOL>result, color=color_lines, alpha=alpha_lines,<EOL>size=size_lines, raise_if_out_of_image=raise_if_out_of_image)<EOL>result = ls_open.draw_points_on_image(<EOL>result, color=color_points, alpha=alpha_points,<EOL>size=size_points, raise_if_out_of_image=raise_if_out_of_image)<EOL>if input_dtype.type == np.uint8:<EOL><INDENT>result = np.clip(np.round(result), <NUM_LIT:0>, <NUM_LIT:255>).astype(input_dtype)  <EOL><DEDENT>else:<EOL><INDENT>result = result.astype(input_dtype)<EOL><DEDENT>return result<EOL>

Draw the polygon on an image.

Parameters
----------
image : (H,W,C) ndarray
    The image onto which to draw the polygon. Usually expected to be
    of dtype ``uint8``, though other dtypes are also handled.

color : iterable of int, optional
    The color to use for the whole polygon.
    Must correspond to the channel layout of the image. Usually RGB.
    The values for `color_face`, `color_lines` and `color_points`
    will be derived from this color if they are set to ``None``.
    This argument has no effect if `color_face`, `color_lines`
    and `color_points` are all set anything other than ``None``.

color_face : None or iterable of int, optional
    The color to use for the inner polygon area (excluding perimeter).
    Must correspond to the channel layout of the image. Usually RGB.
    If this is ``None``, it will be derived from ``color * 1.0``.

color_lines : None or iterable of int, optional
    The color to use for the line (aka perimeter/border) of the polygon.
    Must correspond to the channel layout of the image. Usually RGB.
    If this is ``None``, it will be derived from ``color * 0.5``.

color_points : None or iterable of int, optional
    The color to use for the corner points of the polygon.
    Must correspond to the channel layout of the image. Usually RGB.
    If this is ``None``, it will be derived from ``color * 0.5``.

alpha : float, optional
    The opacity of the whole polygon, where ``1.0`` denotes a completely
    visible polygon and ``0.0`` an invisible one.
    The values for `alpha_face`, `alpha_lines` and `alpha_points`
    will be derived from this alpha value if they are set to ``None``.
    This argument has no effect if `alpha_face`, `alpha_lines`
    and `alpha_points` are all set anything other than ``None``.

alpha_face : None or number, optional
    The opacity of the polygon's inner area (excluding the perimeter),
    where ``1.0`` denotes a completely visible inner area and ``0.0``
    an invisible one.
    If this is ``None``, it will be derived from ``alpha * 0.5``.

alpha_lines : None or number, optional
    The opacity of the polygon's line (aka perimeter/border),
    where ``1.0`` denotes a completely visible line and ``0.0`` an
    invisible one.
    If this is ``None``, it will be derived from ``alpha * 1.0``.

alpha_points : None or number, optional
    The opacity of the polygon's corner points, where ``1.0`` denotes
    completely visible corners and ``0.0`` invisible ones.
    If this is ``None``, it will be derived from ``alpha * 1.0``.

size : int, optional
    Size of the polygon.
    The sizes of the line and points are derived from this value,
    unless they are set.

size_lines : None or int, optional
    Thickness of the polygon's line (aka perimeter/border).
    If ``None``, this value is derived from `size`.

size_points : int, optional
    Size of the points in pixels.
    If ``None``, this value is derived from ``3 * size``.

raise_if_out_of_image : bool, optional
    Whether to raise an error if the polygon is fully
    outside of the image. If set to False, no error will be raised and
    only the parts inside the image will be drawn.

Returns
-------
result : (H,W,C) ndarray
    Image with polygon drawn on it. Result dtype is the same as the input dtype.


ia.do_assert(image.ndim in [<NUM_LIT:2>, <NUM_LIT:3>])<EOL>if len(self.exterior) <= <NUM_LIT:2>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>bb = self.to_bounding_box()<EOL>bb_area = bb.extract_from_image(image)<EOL>if self.is_out_of_image(image, fully=True, partly=False):<EOL><INDENT>return bb_area<EOL><DEDENT>xx = self.xx_int<EOL>yy = self.yy_int<EOL>xx_mask = xx - np.min(xx)<EOL>yy_mask = yy - np.min(yy)<EOL>height_mask = np.max(yy_mask)<EOL>width_mask = np.max(xx_mask)<EOL>rr_face, cc_face = skimage.draw.polygon(yy_mask, xx_mask, shape=(height_mask, width_mask))<EOL>mask = np.zeros((height_mask, width_mask), dtype=np.bool)<EOL>mask[rr_face, cc_face] = True<EOL>if image.ndim == <NUM_LIT:3>:<EOL><INDENT>mask = np.tile(mask[:, :, np.newaxis], (<NUM_LIT:1>, <NUM_LIT:1>, image.shape[<NUM_LIT:2>]))<EOL><DEDENT>return bb_area * mask<EOL>

Extract the image pixels within the polygon.

This function will zero-pad the image if the polygon is partially/fully outside of
the image.

Parameters
----------
image : (H,W) ndarray or (H,W,C) ndarray
    The image from which to extract the pixels within the polygon.

Returns
-------
result : (H',W') ndarray or (H',W',C) ndarray
    Pixels within the polygon. Zero-padded if the polygon is partially/fully
    outside of the image.


def change_first_point_by_coords(self, x, y, max_distance=<NUM_LIT>,<EOL>raise_if_too_far_away=True):

if len(self.exterior) == <NUM_LIT:0>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>closest_idx, closest_dist = self.find_closest_point_index(x=x, y=y, return_distance=True)<EOL>if max_distance is not None and closest_dist > max_distance:<EOL><INDENT>if not raise_if_too_far_away:<EOL><INDENT>return self.deepcopy()<EOL><DEDENT>closest_point = self.exterior[closest_idx, :]<EOL>raise Exception(<EOL>"<STR_LIT>" % (<EOL>closest_point[<NUM_LIT:0>], closest_point[<NUM_LIT:1>], closest_dist)<EOL>)<EOL><DEDENT>return self.change_first_point_by_index(closest_idx)<EOL>

Set the first point of the exterior to the given point based on its coordinates.

If multiple points are found, the closest one will be picked.
If no matching points are found, an exception is raised.

Note: This method does *not* work in-place.

Parameters
----------
x : number
    X-coordinate of the point.

y : number
    Y-coordinate of the point.

max_distance : None or number, optional
    Maximum distance past which possible matches are ignored.
    If ``None`` the distance limit is deactivated.

raise_if_too_far_away : bool, optional
    Whether to raise an exception if the closest found point is too
    far away (``True``) or simply return an unchanged copy if this
    object (``False``).

Returns
-------
imgaug.Polygon
    Copy of this polygon with the new point order.


ia.do_assert(<NUM_LIT:0> <= point_idx < len(self.exterior))<EOL>if point_idx == <NUM_LIT:0>:<EOL><INDENT>return self.deepcopy()<EOL><DEDENT>exterior = np.concatenate(<EOL>(self.exterior[point_idx:, :], self.exterior[:point_idx, :]),<EOL>axis=<NUM_LIT:0><EOL>)<EOL>return self.deepcopy(exterior=exterior)<EOL>

Set the first point of the exterior to the given point based on its index.

Note: This method does *not* work in-place.

Parameters
----------
point_idx : int
    Index of the desired starting point.

Returns
-------
imgaug.Polygon
    Copy of this polygon with the new point order.


<EOL>import shapely.geometry<EOL>return shapely.geometry.Polygon([(point[<NUM_LIT:0>], point[<NUM_LIT:1>]) for point in self.exterior])<EOL>

Convert this polygon to a Shapely polygon.

Returns
-------
shapely.geometry.Polygon
    The Shapely polygon matching this polygon's exterior.


def to_shapely_line_string(self, closed=False, interpolate=<NUM_LIT:0>):

return _convert_points_to_shapely_line_string(self.exterior, closed=closed, interpolate=interpolate)<EOL>

Convert this polygon to a Shapely LineString object.

Parameters
----------
closed : bool, optional
    Whether to return the line string with the last point being identical to the first point.

interpolate : int, optional
    Number of points to interpolate between any pair of two consecutive points. These points are added
    to the final line string.

Returns
-------
shapely.geometry.LineString
    The Shapely LineString matching the polygon's exterior.


<EOL>from imgaug.augmentables.bbs import BoundingBox<EOL>xx = self.xx<EOL>yy = self.yy<EOL>return BoundingBox(x1=min(xx), x2=max(xx), y1=min(yy), y2=max(yy), label=self.label)<EOL>

Convert this polygon to a bounding box tightly containing the whole polygon.

Returns
-------
imgaug.BoundingBox
    Tight bounding box around the polygon.


<EOL>from imgaug.augmentables.kps import Keypoint<EOL>return [Keypoint(x=point[<NUM_LIT:0>], y=point[<NUM_LIT:1>]) for point in self.exterior]<EOL>

Convert this polygon's `exterior` to ``Keypoint`` instances.

Returns
-------
list of imgaug.Keypoint
    Exterior vertices as ``Keypoint`` instances.


from imgaug.augmentables.lines import LineString<EOL>if not closed or len(self.exterior) <= <NUM_LIT:1>:<EOL><INDENT>return LineString(self.exterior, label=self.label)<EOL><DEDENT>return LineString(<EOL>np.concatenate([self.exterior, self.exterior[<NUM_LIT:0>:<NUM_LIT:1>, :]], axis=<NUM_LIT:0>),<EOL>label=self.label)<EOL>

Convert this polygon's `exterior` to a ``LineString`` instance.

Parameters
----------
closed : bool, optional
    Whether to close the line string, i.e. to add the first point of
    the `exterior` also as the last point at the end of the line string.
    This has no effect if the polygon has a single point or zero
    points.

Returns
-------
imgaug.augmentables.lines.LineString
    Exterior of the polygon as a line string.


<EOL>import shapely.geometry<EOL>ia.do_assert(isinstance(polygon_shapely, shapely.geometry.Polygon))<EOL>if polygon_shapely.exterior is None or len(polygon_shapely.exterior.coords) == <NUM_LIT:0>:<EOL><INDENT>return Polygon([], label=label)<EOL><DEDENT>exterior = np.float32([[x, y] for (x, y) in polygon_shapely.exterior.coords])<EOL>return Polygon(exterior, label=label)<EOL>

Create a polygon from a Shapely polygon.

Note: This will remove any holes in the Shapely polygon.

Parameters
----------
polygon_shapely : shapely.geometry.Polygon
     The shapely polygon.

label : None or str, optional
    The label of the new polygon.

Returns
-------
imgaug.Polygon
    A polygon with the same exterior as the Shapely polygon.


def exterior_almost_equals(self, other, max_distance=<NUM_LIT>, points_per_edge=<NUM_LIT:8>):

if isinstance(other, list):<EOL><INDENT>other = Polygon(np.float32(other))<EOL><DEDENT>elif ia.is_np_array(other):<EOL><INDENT>other = Polygon(other)<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(other, Polygon)<EOL>other = other<EOL><DEDENT>return self.to_line_string(closed=True).coords_almost_equals(<EOL>other.to_line_string(closed=True),<EOL>max_distance=max_distance,<EOL>points_per_edge=points_per_edge<EOL>)<EOL>

Estimate if this and other polygon's exterior are almost identical.

The two exteriors can have different numbers of points, but any point
randomly sampled on the exterior of one polygon should be close to the
closest point on the exterior of the other polygon.

Note that this method works approximately. One can come up with
polygons with fairly different shapes that will still be estimated as
equal by this method. In practice however this should be unlikely to be
the case. The probability for something like that goes down as the
interpolation parameter is increased.

Parameters
----------
other : imgaug.Polygon or (N,2) ndarray or list of tuple
    The other polygon with which to compare the exterior.
    If this is an ndarray, it is assumed to represent an exterior.
    It must then have dtype ``float32`` and shape ``(N,2)`` with the
    second dimension denoting xy-coordinates.
    If this is a list of tuples, it is assumed to represent an exterior.
    Each tuple then must contain exactly two numbers, denoting
    xy-coordinates.

max_distance : number, optional
    The maximum euclidean distance between a point on one polygon and
    the closest point on the other polygon. If the distance is exceeded
    for any such pair, the two exteriors are not viewed as equal. The
    points are other the points contained in the polygon's exterior
    ndarray or interpolated points between these.

points_per_edge : int, optional
    How many points to interpolate on each edge.

Returns
-------
bool
    Whether the two polygon's exteriors can be viewed as equal
    (approximate test).


def almost_equals(self, other, max_distance=<NUM_LIT>, points_per_edge=<NUM_LIT:8>):

if not isinstance(other, Polygon):<EOL><INDENT>return False<EOL><DEDENT>if self.label is not None or other.label is not None:<EOL><INDENT>if self.label is None:<EOL><INDENT>return False<EOL><DEDENT>if other.label is None:<EOL><INDENT>return False<EOL><DEDENT>if self.label != other.label:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return self.exterior_almost_equals(<EOL>other, max_distance=max_distance, points_per_edge=points_per_edge)<EOL>

Estimate if this polygon's and another's geometry/labels are similar.

This is the same as :func:`imgaug.Polygon.exterior_almost_equals` but
additionally compares the labels.

Parameters
----------
other
    The object to compare against. If not a Polygon, then False will
    be returned.

max_distance : float, optional
    See :func:`imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

points_per_edge : int, optional
    See :func:`imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

Returns
-------
bool
    Whether the two polygons can be viewed as equal. In the case of
    the exteriors this is an approximate test.


def copy(self, exterior=None, label=None):

return self.deepcopy(exterior=exterior, label=label)<EOL>

Create a shallow copy of the Polygon object.

Parameters
----------
exterior : list of imgaug.Keypoint or list of tuple or (N,2) ndarray, optional
    List of points defining the polygon. See :func:`imgaug.Polygon.__init__` for details.

label : None or str, optional
    If not None, then the label of the copied object will be set to this value.

Returns
-------
imgaug.Polygon
    Shallow copy.


def deepcopy(self, exterior=None, label=None):

return Polygon(<EOL>exterior=np.copy(self.exterior) if exterior is None else exterior,<EOL>label=self.label if label is None else label<EOL>)<EOL>

Create a deep copy of the Polygon object.

Parameters
----------
exterior : list of Keypoint or list of tuple or (N,2) ndarray, optional
    List of points defining the polygon. See `imgaug.Polygon.__init__` for details.

label : None or str
    If not None, then the label of the copied object will be set to this value.

Returns
-------
imgaug.Polygon
    Deep copy.


return len(self.polygons) == <NUM_LIT:0><EOL>

Returns whether this object contains zero polygons.

Returns
-------
bool
    True if this object contains zero polygons.


shape = normalize_shape(image)<EOL>if shape[<NUM_LIT:0>:<NUM_LIT:2>] == self.shape[<NUM_LIT:0>:<NUM_LIT:2>]:<EOL><INDENT>return self.deepcopy()<EOL><DEDENT>polygons = [poly.project(self.shape, shape) for poly in self.polygons]<EOL>return PolygonsOnImage(polygons, shape)<EOL>

Project polygons from one image to a new one.

Parameters
----------
image : ndarray or tuple of int
    New image onto which the polygons are to be projected.
    May also simply be that new image's shape tuple.

Returns
-------
imgaug.PolygonsOnImage
    Object containing all projected polygons.


Draw all polygons onto a given image.

Parameters
----------
image : (H,W,C) ndarray
    The image onto which to draw the bounding boxes.
    This image should usually have the same shape as set in
    ``PolygonsOnImage.shape``.

color : iterable of int, optional
    The color to use for the whole polygons.
    Must correspond to the channel layout of the image. Usually RGB.
    The values for `color_face`, `color_lines` and `color_points`
    will be derived from this color if they are set to ``None``.
    This argument has no effect if `color_face`, `color_lines`
    and `color_points` are all set anything other than ``None``.

color_face : None or iterable of int, optional
    The color to use for the inner polygon areas (excluding perimeters).
    Must correspond to the channel layout of the image. Usually RGB.
    If this is ``None``, it will be derived from ``color * 1.0``.

color_lines : None or iterable of int, optional
    The color to use for the lines (aka perimeters/borders) of the
    polygons. Must correspond to the channel layout of the image.
    Usually RGB. If this is ``None``, it will be derived
    from ``color * 0.5``.

color_points : None or iterable of int, optional
    The color to use for the corner points of the polygons.
    Must correspond to the channel layout of the image. Usually RGB.
    If this is ``None``, it will be derived from ``color * 0.5``.

alpha : float, optional
    The opacity of the whole polygons, where ``1.0`` denotes
    completely visible polygons and ``0.0`` invisible ones.
    The values for `alpha_face`, `alpha_lines` and `alpha_points`
    will be derived from this alpha value if they are set to ``None``.
    This argument has no effect if `alpha_face`, `alpha_lines`
    and `alpha_points` are all set anything other than ``None``.

alpha_face : None or number, optional
    The opacity of the polygon's inner areas (excluding the perimeters),
    where ``1.0`` denotes completely visible inner areas and ``0.0``
    invisible ones.
    If this is ``None``, it will be derived from ``alpha * 0.5``.

alpha_lines : None or number, optional
    The opacity of the polygon's lines (aka perimeters/borders),
    where ``1.0`` denotes completely visible perimeters and ``0.0``
    invisible ones.
    If this is ``None``, it will be derived from ``alpha * 1.0``.

alpha_points : None or number, optional
    The opacity of the polygon's corner points, where ``1.0`` denotes
    completely visible corners and ``0.0`` invisible ones.
    Currently this is an on/off choice, i.e. only ``0.0`` or ``1.0``
    are allowed.
    If this is ``None``, it will be derived from ``alpha * 1.0``.

size : int, optional
    Size of the polygons.
    The sizes of the line and points are derived from this value,
    unless they are set.

size_lines : None or int, optional
    Thickness of the polygon lines (aka perimeter/border).
    If ``None``, this value is derived from `size`.

size_points : int, optional
    The size of all corner points. If set to ``C``, each corner point
    will be drawn as a square of size ``C x C``.

raise_if_out_of_image : bool, optional
    Whether to raise an error if any polygon is fully
    outside of the image. If set to False, no error will be raised and
    only the parts inside the image will be drawn.

Returns
-------
image : (H,W,C) ndarray
    Image with drawn polygons.


def remove_out_of_image(self, fully=True, partly=False):

polys_clean = [<EOL>poly for poly in self.polygons<EOL>if not poly.is_out_of_image(self.shape, fully=fully, partly=partly)<EOL>]<EOL>return PolygonsOnImage(polys_clean, shape=self.shape)<EOL>

Remove all polygons that are fully or partially outside of the image.

Parameters
----------
fully : bool, optional
    Whether to remove polygons that are fully outside of the image.

partly : bool, optional
    Whether to remove polygons that are partially outside of the image.

Returns
-------
imgaug.PolygonsOnImage
    Reduced set of polygons, with those that were fully/partially
    outside of the image removed.


polys_cut = [<EOL>poly.clip_out_of_image(self.shape)<EOL>for poly<EOL>in self.polygons<EOL>if poly.is_partly_within_image(self.shape)<EOL>]<EOL>polys_cut_flat = [poly for poly_lst in polys_cut for poly in poly_lst]<EOL>return PolygonsOnImage(polys_cut_flat, shape=self.shape)<EOL>

Clip off all parts from all polygons that are outside of the image.

NOTE: The result can contain less polygons than the input did. That
happens when a polygon is fully outside of the image plane.

NOTE: The result can also contain *more* polygons than the input
did. That happens when distinct parts of a polygon are only
connected by areas that are outside of the image plane and hence will
be clipped off, resulting in two or more unconnected polygon parts that
are left in the image plane.

Returns
-------
imgaug.PolygonsOnImage
    Polygons, clipped to fall within the image dimensions. Count of
    output polygons may differ from the input count.


polys_new = [<EOL>poly.shift(top=top, right=right, bottom=bottom, left=left)<EOL>for poly<EOL>in self.polygons<EOL>]<EOL>return PolygonsOnImage(polys_new, shape=self.shape)<EOL>

Shift all polygons from one or more image sides, i.e. move them on the x/y-axis.

Parameters
----------
top : None or int, optional
    Amount of pixels by which to shift all polygons from the top.

right : None or int, optional
    Amount of pixels by which to shift all polygons from the right.

bottom : None or int, optional
    Amount of pixels by which to shift all polygons from the bottom.

left : None or int, optional
    Amount of pixels by which to shift all polygons from the left.

Returns
-------
imgaug.PolygonsOnImage
    Shifted polygons.


return copy.copy(self)<EOL>

Create a shallow copy of the PolygonsOnImage object.

Returns
-------
imgaug.PolygonsOnImage
    Shallow copy.


<EOL>polys = [poly.deepcopy() for poly in self.polygons]<EOL>return PolygonsOnImage(polys, tuple(self.shape))<EOL>

Create a deep copy of the PolygonsOnImage object.

Returns
-------
imgaug.PolygonsOnImage
    Deep copy.


ia.do_assert(len(geoms) == <NUM_LIT:0> or all([isinstance(el, Polygon) for el in geoms]))<EOL>self.geoms = geoms<EOL>


<EOL>import shapely.geometry<EOL>if isinstance(geometry, shapely.geometry.MultiPolygon):<EOL><INDENT>return MultiPolygon([Polygon.from_shapely(poly, label=label) for poly in geometry.geoms])<EOL><DEDENT>elif isinstance(geometry, shapely.geometry.Polygon):<EOL><INDENT>return MultiPolygon([Polygon.from_shapely(geometry, label=label)])<EOL><DEDENT>elif isinstance(geometry, shapely.geometry.collection.GeometryCollection):<EOL><INDENT>ia.do_assert(all([isinstance(poly, shapely.geometry.Polygon) for poly in geometry.geoms]))<EOL>return MultiPolygon([Polygon.from_shapely(poly, label=label) for poly in geometry.geoms])<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (type(geometry),))<EOL><DEDENT>

Create a MultiPolygon from a Shapely MultiPolygon, a Shapely Polygon or a Shapely GeometryCollection.

This also creates all necessary Polygons contained by this MultiPolygon.

Parameters
----------
geometry : shapely.geometry.MultiPolygon or shapely.geometry.Polygon\
           or shapely.geometry.collection.GeometryCollection
    The object to convert to a MultiPolygon.

label : None or str, optional
    A label assigned to all Polygons within the MultiPolygon.

Returns
-------
imgaug.MultiPolygon
    The derived MultiPolygon.


if isinstance(shape, tuple):<EOL><INDENT>return shape<EOL><DEDENT>assert ia.is_np_array(shape), (<EOL>"<STR_LIT>" % (type(shape),))<EOL>return shape.shape<EOL>

Normalize a shape tuple or array to a shape tuple.

Parameters
----------
shape : tuple of int or ndarray
    The input to normalize. May optionally be an array.

Returns
-------
tuple of int
    Shape tuple.


def project_coords(coords, from_shape, to_shape):

from_shape = normalize_shape(from_shape)<EOL>to_shape = normalize_shape(to_shape)<EOL>if from_shape[<NUM_LIT:0>:<NUM_LIT:2>] == to_shape[<NUM_LIT:0>:<NUM_LIT:2>]:<EOL><INDENT>return coords<EOL><DEDENT>from_height, from_width = from_shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>to_height, to_width = to_shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>assert all([v > <NUM_LIT:0> for v in [from_height, from_width, to_height, to_width]])<EOL>coords_proj = np.array(coords).astype(np.float32)<EOL>coords_proj[:, <NUM_LIT:0>] = (coords_proj[:, <NUM_LIT:0>] / from_width) * to_width<EOL>coords_proj[:, <NUM_LIT:1>] = (coords_proj[:, <NUM_LIT:1>] / from_height) * to_height<EOL>return coords_proj<EOL>

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 at 60% of the new image width after projection.

Parameters
----------
coords : ndarray or tuple of number
    Coordinates to project. Either a ``(N,2)`` numpy array or a tuple
    of `(x,y)` coordinates.

from_shape : tuple of int or ndarray
    Old image shape.

to_shape : tuple of int or ndarray
    New image shape.

Returns
-------
ndarray
    Projected coordinates as ``(N,2)`` ``float32`` numpy array.


def get_arr_int(self, background_threshold=<NUM_LIT>, background_class_id=None):

if self.input_was[<NUM_LIT:0>] in ["<STR_LIT:bool>", "<STR_LIT:float>"]:<EOL><INDENT>ia.do_assert(background_class_id is None,<EOL>"<STR_LIT>"<EOL>+ "<STR_LIT>")<EOL><DEDENT>if background_class_id is None:<EOL><INDENT>background_class_id = <NUM_LIT:0><EOL><DEDENT>channelwise_max_idx = np.argmax(self.arr, axis=<NUM_LIT:2>)<EOL>if self.input_was[<NUM_LIT:0>] in ["<STR_LIT:bool>", "<STR_LIT:float>"]:<EOL><INDENT>result = <NUM_LIT:1> + channelwise_max_idx<EOL><DEDENT>else:  <EOL><INDENT>result = channelwise_max_idx<EOL><DEDENT>if background_threshold is not None and background_threshold > <NUM_LIT:0>:<EOL><INDENT>probs = np.amax(self.arr, axis=<NUM_LIT:2>)<EOL>result[probs < background_threshold] = background_class_id<EOL><DEDENT>return result.astype(np.int32)<EOL>

Get the segmentation map array as an integer array of shape (H, W).

Each pixel in that array contains an integer value representing the pixel's class.
If multiple classes overlap, the one with the highest local float value is picked.
If that highest local value is below `background_threshold`, the method instead uses
the background class id as the pixel's class value.
By default, class id 0 is the background class. This may only be changed if the original
input to the segmentation map object was an integer map.

Parameters
----------
background_threshold : float, optional
    At each pixel, each class-heatmap has a value between 0.0 and 1.0. If none of the
    class-heatmaps has a value above this threshold, the method uses the background class
    id instead.

background_class_id : None or int, optional
    Class id to fall back to if no class-heatmap passes the threshold at a spatial
    location. May only be provided if the original input was an integer mask and in these
    cases defaults to 0. If the input were float or boolean masks, the background class id
    may not be set as it is assumed that the background is implicitly defined
    as 'any spatial location that has zero-like values in all masks'.

Returns
-------
result : (H,W) ndarray
    Segmentation map array (int32).
    If the original input consisted of boolean or float masks, then the highest possible
    class id is ``1+C``, where ``C`` is the number of provided float/boolean masks. The value
    ``0`` in the integer mask then denotes the background class.


def draw(self, size=None, background_threshold=<NUM_LIT>, background_class_id=None, colors=None,<EOL>return_foreground_mask=False):

arr = self.get_arr_int(background_threshold=background_threshold, background_class_id=background_class_id)<EOL>nb_classes = <NUM_LIT:1> + np.max(arr)<EOL>segmap_drawn = np.zeros((arr.shape[<NUM_LIT:0>], arr.shape[<NUM_LIT:1>], <NUM_LIT:3>), dtype=np.uint8)<EOL>if colors is None:<EOL><INDENT>colors = SegmentationMapOnImage.DEFAULT_SEGMENT_COLORS<EOL><DEDENT>ia.do_assert(nb_classes <= len(colors),<EOL>"<STR_LIT>" % (<EOL>nb_classes, len(colors),))<EOL>ids_in_map = np.unique(arr)<EOL>for c, color in zip(sm.xrange(nb_classes), colors):<EOL><INDENT>if c in ids_in_map:<EOL><INDENT>class_mask = (arr == c)<EOL>segmap_drawn[class_mask] = color<EOL><DEDENT><DEDENT>if return_foreground_mask:<EOL><INDENT>background_class_id = <NUM_LIT:0> if background_class_id is None else background_class_id<EOL>foreground_mask = (arr != background_class_id)<EOL><DEDENT>else:<EOL><INDENT>foreground_mask = None<EOL><DEDENT>if size is not None:<EOL><INDENT>segmap_drawn = ia.imresize_single_image(segmap_drawn, size, interpolation="<STR_LIT>")<EOL>if foreground_mask is not None:<EOL><INDENT>foreground_mask = ia.imresize_single_image(<EOL>foreground_mask.astype(np.uint8), size, interpolation="<STR_LIT>") > <NUM_LIT:0><EOL><DEDENT><DEDENT>if foreground_mask is not None:<EOL><INDENT>return segmap_drawn, foreground_mask<EOL><DEDENT>return segmap_drawn<EOL>

Render the segmentation map as an RGB image.

Parameters
----------
size : None or float or iterable of int or iterable of float, optional
    Size of the rendered RGB image as ``(height, width)``.
    See :func:`imgaug.imgaug.imresize_single_image` for details.
    If set to None, no resizing is performed and the size of the segmentation map array is used.

background_threshold : float, optional
    See :func:`imgaug.SegmentationMapOnImage.get_arr_int`.

background_class_id : None or int, optional
    See :func:`imgaug.SegmentationMapOnImage.get_arr_int`.

colors : None or list of tuple of int, optional
    Colors to use. One for each class to draw. If None, then default colors will be used.

return_foreground_mask : bool, optional
    Whether to return a mask of the same size as the drawn segmentation map, containing
    True at any spatial location that is not the background class and False everywhere else.

Returns
-------
segmap_drawn : (H,W,3) ndarray
    Rendered segmentation map (dtype is uint8).

foreground_mask : (H,W) ndarray
    Mask indicating the locations of foreground classes (dtype is bool).
    This value is only returned if `return_foreground_mask` is True.


def draw_on_image(self, image, alpha=<NUM_LIT>, resize="<STR_LIT>", background_threshold=<NUM_LIT>,<EOL>background_class_id=None, colors=None, draw_background=False):

<EOL>ia.do_assert(image.ndim == <NUM_LIT:3>)<EOL>ia.do_assert(image.shape[<NUM_LIT:2>] == <NUM_LIT:3>)<EOL>ia.do_assert(image.dtype.type == np.uint8)<EOL>ia.do_assert(<NUM_LIT:0> - <NUM_LIT> <= alpha <= <NUM_LIT:1.0> + <NUM_LIT>)<EOL>ia.do_assert(resize in ["<STR_LIT>", "<STR_LIT:image>"])<EOL>if resize == "<STR_LIT:image>":<EOL><INDENT>image = ia.imresize_single_image(image, self.arr.shape[<NUM_LIT:0>:<NUM_LIT:2>], interpolation="<STR_LIT>")<EOL><DEDENT>segmap_drawn, foreground_mask = self.draw(<EOL>background_threshold=background_threshold,<EOL>background_class_id=background_class_id,<EOL>size=image.shape[<NUM_LIT:0>:<NUM_LIT:2>] if resize == "<STR_LIT>" else None,<EOL>colors=colors,<EOL>return_foreground_mask=True<EOL>)<EOL>if draw_background:<EOL><INDENT>mix = np.clip(<EOL>(<NUM_LIT:1>-alpha) * image + alpha * segmap_drawn,<EOL><NUM_LIT:0>,<EOL><NUM_LIT:255><EOL>).astype(np.uint8)<EOL><DEDENT>else:<EOL><INDENT>foreground_mask = foreground_mask[..., np.newaxis]<EOL>mix = np.zeros_like(image)<EOL>mix += (~foreground_mask).astype(np.uint8) * image<EOL>mix += foreground_mask.astype(np.uint8) * np.clip(<EOL>(<NUM_LIT:1>-alpha) * image + alpha * segmap_drawn,<EOL><NUM_LIT:0>,<EOL><NUM_LIT:255><EOL>).astype(np.uint8)<EOL><DEDENT>return mix<EOL>

Draw the segmentation map as an overlay over an image.

Parameters
----------
image : (H,W,3) ndarray
    Image onto which to draw the segmentation map. Dtype is expected to be uint8.

alpha : float, optional
    Alpha/opacity value to use for the mixing of image and segmentation map.
    Higher values mean that the segmentation map will be more visible and the image less visible.

resize : {'segmentation_map', 'image'}, optional
    In case of size differences between the image and segmentation map, either the image or
    the segmentation map can be resized. This parameter controls which of the two will be
    resized to the other's size.

background_threshold : float, optional
    See :func:`imgaug.SegmentationMapOnImage.get_arr_int`.

background_class_id : None or int, optional
    See :func:`imgaug.SegmentationMapOnImage.get_arr_int`.

colors : None or list of tuple of int, optional
    Colors to use. One for each class to draw. If None, then default colors will be used.

draw_background : bool, optional
    If True, the background will be drawn like any other class.
    If False, the background will not be drawn, i.e. the respective background pixels
    will be identical with the image's RGB color at the corresponding spatial location
    and no color overlay will be applied.

Returns
-------
mix : (H,W,3) ndarray
    Rendered overlays (dtype is uint8).


def pad(self, top=<NUM_LIT:0>, right=<NUM_LIT:0>, bottom=<NUM_LIT:0>, left=<NUM_LIT:0>, mode="<STR_LIT>", cval=<NUM_LIT:0.0>):

arr_padded = ia.pad(self.arr, top=top, right=right, bottom=bottom, left=left, mode=mode, cval=cval)<EOL>segmap = SegmentationMapOnImage(arr_padded, shape=self.shape)<EOL>segmap.input_was = self.input_was<EOL>return segmap<EOL>

Pad the segmentation map on its top/right/bottom/left side.

Parameters
----------
top : int, optional
    Amount of pixels to add at the top side of the segmentation map. Must be 0 or greater.

right : int, optional
    Amount of pixels to add at the right side of the segmentation map. Must be 0 or greater.

bottom : int, optional
    Amount of pixels to add at the bottom side of the segmentation map. Must be 0 or greater.

left : int, optional
    Amount of pixels to add at the left side of the segmentation map. Must be 0 or greater.

mode : str, optional
    Padding mode to use. See :func:`numpy.pad` for details.

cval : number, optional
    Value to use for padding if `mode` is ``constant``. See :func:`numpy.pad` for details.

Returns
-------
segmap : imgaug.SegmentationMapOnImage
    Padded segmentation map of height ``H'=H+top+bottom`` and width ``W'=W+left+right``.


def pad_to_aspect_ratio(self, aspect_ratio, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, return_pad_amounts=False):

arr_padded, pad_amounts = ia.pad_to_aspect_ratio(self.arr, aspect_ratio=aspect_ratio, mode=mode, cval=cval,<EOL>return_pad_amounts=True)<EOL>segmap = SegmentationMapOnImage(arr_padded, shape=self.shape)<EOL>segmap.input_was = self.input_was<EOL>if return_pad_amounts:<EOL><INDENT>return segmap, pad_amounts<EOL><DEDENT>else:<EOL><INDENT>return segmap<EOL><DEDENT>

Pad the segmentation map on its sides so that its matches a target aspect ratio.

Depending on which dimension is smaller (height or width), only the corresponding
sides (left/right or top/bottom) will be padded. In each case, both of the sides will
be padded equally.

Parameters
----------
aspect_ratio : float
    Target aspect ratio, given as width/height. E.g. 2.0 denotes the image having twice
    as much width as height.

mode : str, optional
    Padding mode to use. See :func:`numpy.pad` for details.

cval : number, optional
    Value to use for padding if `mode` is ``constant``. See :func:`numpy.pad` for details.

return_pad_amounts : bool, optional
    If False, then only the padded image will be returned. If True, a tuple with two
    entries will be returned, where the first entry is the padded image and the second
    entry are the amounts by which each image side was padded. These amounts are again a
    tuple of the form (top, right, bottom, left), with each value being an integer.

Returns
-------
segmap : imgaug.SegmentationMapOnImage
    Padded segmentation map as SegmentationMapOnImage object.

pad_amounts : tuple of int
    Amounts by which the segmentation map was padded on each side, given as a
    tuple ``(top, right, bottom, left)``.
    This tuple is only returned if `return_pad_amounts` was set to True.


def resize(self, sizes, interpolation="<STR_LIT>"):

arr_resized = ia.imresize_single_image(self.arr, sizes, interpolation=interpolation)<EOL>arr_resized = np.clip(arr_resized, <NUM_LIT:0.0>, <NUM_LIT:1.0>)<EOL>segmap = SegmentationMapOnImage(arr_resized, shape=self.shape)<EOL>segmap.input_was = self.input_was<EOL>return segmap<EOL>

Resize the segmentation map array to the provided size given the provided interpolation.

Parameters
----------
sizes : float or iterable of int or iterable of float
    New size of the array in ``(height, width)``.
    See :func:`imgaug.imgaug.imresize_single_image` for details.

interpolation : None or str or int, optional
    The interpolation to use during resize.
    See :func:`imgaug.imgaug.imresize_single_image` for details.
    Note: The segmentation map is internally stored as multiple float-based heatmaps,
    making smooth interpolations potentially more reasonable than nearest neighbour
    interpolation.

Returns
-------
segmap : imgaug.SegmentationMapOnImage
    Resized segmentation map object.


def to_heatmaps(self, only_nonempty=False, not_none_if_no_nonempty=False):

<EOL>from imgaug.augmentables.heatmaps import HeatmapsOnImage<EOL>if not only_nonempty:<EOL><INDENT>return HeatmapsOnImage.from_0to1(self.arr, self.shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>)<EOL><DEDENT>else:<EOL><INDENT>nonempty_mask = np.sum(self.arr, axis=(<NUM_LIT:0>, <NUM_LIT:1>)) > <NUM_LIT:0> + <NUM_LIT><EOL>if np.sum(nonempty_mask) == <NUM_LIT:0>:<EOL><INDENT>if not_none_if_no_nonempty:<EOL><INDENT>nonempty_mask[<NUM_LIT:0>] = True<EOL><DEDENT>else:<EOL><INDENT>return None, []<EOL><DEDENT><DEDENT>class_indices = np.arange(self.arr.shape[<NUM_LIT:2>])[nonempty_mask]<EOL>channels = self.arr[..., class_indices]<EOL>return HeatmapsOnImage(channels, self.shape, min_value=<NUM_LIT:0.0>, max_value=<NUM_LIT:1.0>), class_indices<EOL><DEDENT>

Convert segmentation map to heatmaps object.

Each segmentation map class will be represented as a single heatmap channel.

Parameters
----------
only_nonempty : bool, optional
    If True, then only heatmaps for classes that appear in the segmentation map will be
    generated. Additionally, a list of these class ids will be returned.

not_none_if_no_nonempty : bool, optional
    If `only_nonempty` is True and for a segmentation map no channel was non-empty,
    this function usually returns None as the heatmaps object. If however this parameter
    is set to True, a heatmaps object with one channel (representing class 0)
    will be returned as a fallback in these cases.

Returns
-------
imgaug.HeatmapsOnImage or None
    Segmentation map as a heatmaps object.
    If `only_nonempty` was set to True and no class appeared in the segmentation map,
    then this is None.

class_indices : list of int
    Class ids (0 to C-1) of the classes that were actually added to the heatmaps.
    Only returned if `only_nonempty` was set to True.


@staticmethod<EOL><INDENT>def from_heatmaps(heatmaps, class_indices=None, nb_classes=None):<DEDENT>

if class_indices is None:<EOL><INDENT>return SegmentationMapOnImage(heatmaps.arr_0to1, shape=heatmaps.shape)<EOL><DEDENT>else:<EOL><INDENT>ia.do_assert(nb_classes is not None)<EOL>ia.do_assert(min(class_indices) >= <NUM_LIT:0>)<EOL>ia.do_assert(max(class_indices) < nb_classes)<EOL>ia.do_assert(len(class_indices) == heatmaps.arr_0to1.shape[<NUM_LIT:2>])<EOL>arr_0to1 = heatmaps.arr_0to1<EOL>arr_0to1_full = np.zeros((arr_0to1.shape[<NUM_LIT:0>], arr_0to1.shape[<NUM_LIT:1>], nb_classes), dtype=np.float32)<EOL>for heatmap_channel, mapped_channel in enumerate(class_indices):<EOL><INDENT>arr_0to1_full[:, :, mapped_channel] = arr_0to1[:, :, heatmap_channel]<EOL><DEDENT>return SegmentationMapOnImage(arr_0to1_full, shape=heatmaps.shape)<EOL><DEDENT>

Convert heatmaps to segmentation map.

Assumes that each class is represented as a single heatmap channel.

Parameters
----------
heatmaps : imgaug.HeatmapsOnImage
    Heatmaps to convert.

class_indices : None or list of int, optional
    List of class indices represented by each heatmap channel. See also the
    secondary output of :func:`imgaug.SegmentationMapOnImage.to_heatmap`.
    If this is provided, it must have the same length as the number of heatmap channels.

nb_classes : None or int, optional
    Number of classes. Must be provided if class_indices is set.

Returns
-------
imgaug.SegmentationMapOnImage
    Segmentation map derived from heatmaps.


return self.deepcopy()<EOL>

Create a shallow copy of the segmentation map object.

Returns
-------
imgaug.SegmentationMapOnImage
    Shallow copy.


segmap = SegmentationMapOnImage(self.arr, shape=self.shape, nb_classes=self.nb_classes)<EOL>segmap.input_was = self.input_was<EOL>return segmap<EOL>

Create a deep copy of the segmentation map object.

Returns
-------
imgaug.SegmentationMapOnImage
    Deep copy.


def Clouds(name=None, deterministic=False, random_state=None):

if name is None:<EOL><INDENT>name = "<STR_LIT>" % (ia.caller_name(),)<EOL><DEDENT>return meta.SomeOf((<NUM_LIT:1>, <NUM_LIT:2>), children=[<EOL>CloudLayer(<EOL>intensity_mean=(<NUM_LIT>, <NUM_LIT:255>), intensity_freq_exponent=(-<NUM_LIT>, -<NUM_LIT>), intensity_coarse_scale=<NUM_LIT:10>,<EOL>alpha_min=<NUM_LIT:0>, alpha_multiplier=(<NUM_LIT>, <NUM_LIT>), alpha_size_px_max=(<NUM_LIT:2>, <NUM_LIT:8>), alpha_freq_exponent=(-<NUM_LIT>, -<NUM_LIT>),<EOL>sparsity=(<NUM_LIT>, <NUM_LIT:1.0>), density_multiplier=(<NUM_LIT:0.5>, <NUM_LIT:1.0>)<EOL>),<EOL>CloudLayer(<EOL>intensity_mean=(<NUM_LIT>, <NUM_LIT:255>), intensity_freq_exponent=(-<NUM_LIT>, -<NUM_LIT:1.0>), intensity_coarse_scale=<NUM_LIT:10>,<EOL>alpha_min=<NUM_LIT:0>, alpha_multiplier=(<NUM_LIT:0.5>, <NUM_LIT:1.0>), alpha_size_px_max=(<NUM_LIT:64>, <NUM_LIT>), alpha_freq_exponent=(-<NUM_LIT>, -<NUM_LIT:1.0>),<EOL>sparsity=(<NUM_LIT:1.0>, <NUM_LIT>), density_multiplier=(<NUM_LIT>, <NUM_LIT>)<EOL>)<EOL>], random_order=False, name=name, deterministic=deterministic, random_state=random_state)<EOL>

Augmenter to draw clouds in images.

This is a wrapper around ``CloudLayer``. It executes 1 to 2 layers per image, leading to varying densities
and frequency patterns of clouds.

This augmenter seems to be fairly robust w.r.t. the image size. Tested with ``96x128``, ``192x256``
and ``960x1280``.

dtype support::

    * ``uint8``: yes; tested
    * ``uint16``: no (1)
    * ``uint32``: no (1)
    * ``uint64``: no (1)
    * ``int8``: no (1)
    * ``int16``: no (1)
    * ``int32``: no (1)
    * ``int64``: no (1)
    * ``float16``: no (1)
    * ``float32``: no (1)
    * ``float64``: no (1)
    * ``float128``: no (1)
    * ``bool``: no (1)

    - (1) Parameters of this augmenter are optimized for the value range of uint8.
          While other dtypes may be accepted, they will lead to images augmented in
          ways inappropriate for the respective dtype.

Parameters
----------
name : None or str, optional
    See :func:`imgaug.augmenters.meta.Augmenter.__init__`.

deterministic : bool, optional
    See :func:`imgaug.augmenters.meta.Augmenter.__init__`.

random_state : None or int or numpy.random.RandomState, optional
    See :func:`imgaug.augmenters.meta.Augmenter.__init__`.

Examples
--------
>>> aug = iaa.Clouds()

Creates an augmenter that adds clouds to images.