def clip_out_of_image(self, image):
<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.