def draw_lines_on_image(self, image, color=(<NUM_LIT:0>, <NUM_LIT:255>, <NUM_LIT:0>),<EOL>alpha=<NUM_LIT:1.0>, size=<NUM_LIT:3>,<EOL>antialiased=True,<EOL>raise_if_out_of_image=False):
from .. import dtypes as iadt<EOL>from ..augmenters import blend as blendlib<EOL>image_was_empty = False<EOL>if isinstance(image, tuple):<EOL><INDENT>image_was_empty = True<EOL>image = np.zeros(image, dtype=np.uint8)<EOL><DEDENT>assert image.ndim in [<NUM_LIT:2>, <NUM_LIT:3>], (<EOL>("<STR_LIT>"<EOL>+ "<STR_LIT>") % (image.shape,))<EOL>if len(self.coords) <= <NUM_LIT:1> or alpha < <NUM_LIT:0> + <NUM_LIT> or size < <NUM_LIT:1>:<EOL><INDENT>return np.copy(image)<EOL><DEDENT>if raise_if_out_of_imageand self.is_out_of_image(image, partly=False, fully=True):<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>self.__str__(), image.shape))<EOL><DEDENT>if image.ndim == <NUM_LIT:2>:<EOL><INDENT>assert ia.is_single_number(color), (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (str(color),))<EOL>color = [color]<EOL><DEDENT>elif image.ndim == <NUM_LIT:3> and ia.is_single_number(color):<EOL><INDENT>color = [color] * image.shape[-<NUM_LIT:1>]<EOL><DEDENT>image = image.astype(np.float32)<EOL>height, width = image.shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>lines = []<EOL>for line_start, line_end in zip(self.coords[:-<NUM_LIT:1>], self.coords[<NUM_LIT:1>:]):<EOL><INDENT>lines.append((line_start[<NUM_LIT:1>], line_start[<NUM_LIT:0>],<EOL>line_end[<NUM_LIT:1>], line_end[<NUM_LIT:0>]))<EOL><DEDENT>lines = np.round(np.float32(lines)).astype(np.int32)<EOL>color = np.float32(color)<EOL>heatmap = np.zeros(image.shape[<NUM_LIT:0>:<NUM_LIT:2>], dtype=np.float32)<EOL>for line in lines:<EOL><INDENT>if antialiased:<EOL><INDENT>rr, cc, val = skimage.draw.line_aa(*line)<EOL><DEDENT>else:<EOL><INDENT>rr, cc = skimage.draw.line(*line)<EOL>val = <NUM_LIT:1.0><EOL><DEDENT>rr_mask = np.logical_and(<NUM_LIT:0> <= rr, rr < height)<EOL>cc_mask = np.logical_and(<NUM_LIT:0> <= cc, cc < width)<EOL>mask = np.logical_and(rr_mask, cc_mask)<EOL>if np.any(mask):<EOL><INDENT>rr = rr[mask]<EOL>cc = cc[mask]<EOL>val = val[mask] if not ia.is_single_number(val) else val<EOL>heatmap[rr, cc] = val * alpha<EOL><DEDENT><DEDENT>if size > <NUM_LIT:1>:<EOL><INDENT>kernel = np.ones((size, size), dtype=np.uint8)<EOL>heatmap = cv2.dilate(heatmap, kernel)<EOL><DEDENT>if image_was_empty:<EOL><INDENT>image_blend = image + heatmap * color<EOL><DEDENT>else:<EOL><INDENT>image_color_shape = image.shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>if image.ndim == <NUM_LIT:3>:<EOL><INDENT>image_color_shape = image_color_shape + (<NUM_LIT:1>,)<EOL><DEDENT>image_color = np.tile(color, image_color_shape)<EOL>image_blend = blendlib.blend_alpha(image_color, image, heatmap)<EOL><DEDENT>image_blend = iadt.restore_dtypes_(image_blend, np.uint8)<EOL>return image_blend<EOL>
Draw the line segments of the line string on a given image.

Parameters
----------
image : ndarray or tuple of int
    The image onto which to draw.
    Expected to be ``uint8`` and of shape ``(H, W, C)`` with ``C``
    usually being ``3`` (other values are not tested).
    If a tuple, expected to be ``(H, W, C)`` and will lead to a new
    ``uint8`` array of zeros being created.

color : int or iterable of int
    Color to use as RGB, i.e. three values.

alpha : float, optional
    Opacity of the line string. Higher values denote a more visible
    line string.

size : int, optional
    Thickness of the line segments.

antialiased : bool, optional
    Whether to draw the line with anti-aliasing activated.

raise_if_out_of_image : bool, optional
    Whether to raise an error if the line string 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
-------
ndarray
    `image` with line drawn on it.