def gen_shape_image(im_size: Tuple[(int, int)], max_shapes: int=10, overlap: bool=False, rotation: bool=False):
    (img, shapes) = random_shapes(im_size, max_shapes, min_size=25, max_size=150, multichannel=False, allow_overlap=overlap)
    labels = np.zeros(im_size)
    shape_map = {'circle': 1, 'rectangle': 2, 'triangle': 3}
    for (shape, coords) in shapes:
        (rr, cc) = coords
        shape_img = img[rr[0]:rr[1], cc[0]:cc[1]]
        colors = np.bincount(shape_img.ravel()).argsort()
        shape_color = (colors[(- 1)] if (colors[(- 1)] != 255) else colors[(- 2)])
        (shape_rr, shape_cc) = np.where((shape_img == shape_color))
        shape_rr += rr[0]
        shape_cc += cc[0]
        labels[(shape_rr, shape_cc)] = shape_map[shape]
    if rotation:
        angle = np.random.uniform((- 180), 180)
        img = rotate(img, angle, preserve_range=True, resize=True, cval=255).astype(np.int)
        labels = rotate(labels, angle, preserve_range=True, resize=True).astype(np.int)
    background = 255
    while (background in np.unique(img)):
        background = np.random.randint(0, 255)
    img[(img == 255)] = background
    return (img.astype(np.int), labels.astype(np.int))
def gen_shape_image(im_size: Tuple[(int, int)], max_shapes: int=10, overlap: bool=False, rotation: bool=False):
    (img, shapes) = random_shapes(im_size, max_shapes, min_size=25, max_size=150, multichannel=False, allow_overlap=overlap)
    labels = np.zeros(im_size)
    shape_map = {'circle': 1, 'rectangle': 2, 'triangle': 3}
    for (shape, coords) in shapes:
        (rr, cc) = coords
        shape_img = img[rr[0]:rr[1], cc[0]:cc[1]]
        colors = np.bincount(shape_img.ravel()).argsort()
        shape_color = (colors[(- 1)] if (colors[(- 1)] != 255) else colors[(- 2)])
        (shape_rr, shape_cc) = np.where((shape_img == shape_color))
        shape_rr += rr[0]
        shape_cc += cc[0]
        labels[(shape_rr, shape_cc)] = shape_map[shape]
    if rotation:
        angle = np.random.uniform((- 180), 180)
        img = rotate(img, angle, preserve_range=True, resize=True, cval=255).astype(np.int)
        labels = rotate(labels, angle, preserve_range=True, resize=True).astype(np.int)
    background = 255
    while (background in np.unique(img)):
        background = np.random.randint(0, 255)
    img[(img == 255)] = background
    return (img.astype(np.int), labels.astype(np.int))