def polygons2mask_layer(height, width, polygon, image_id, i):
    """

    :param height:
    :param width:
    :param polygons:
    :return:
    """

    x_max, y_min = extra_functions._get_xmax_ymin(image_id)
    x_scaler, y_scaler = extra_functions.get_scalers(height, width, x_max,
                                                     y_min)

    polygons = shapely.affinity.scale(polygon,
                                      xfact=x_scaler,
                                      yfact=y_scaler,
                                      origin=(0, 0, 0))
    img_mask = np.zeros((height, width), np.uint8)

    if not polygons:
        return img_mask

    int_coords = lambda x: np.array(x).round().astype(np.int32)
    exteriors = [int_coords(poly.exterior.coords) for poly in polygons]
    interiors = [
        int_coords(pi.coords) for poly in polygons for pi in poly.interiors
    ]

    cv2.fillPoly(img_mask, exteriors, 11 - i)
    cv2.fillPoly(img_mask, interiors, 0)

    return img_mask
    return shapely.wkt.dumps(polygons.buffer(2.6e-5))


#%%
for image_id in tqdm(test_ids):
    image = extra_functions.read_image_16(image_id)

    file_name = '{}.tif'.format(image_id)
    image_3 = tiff.imread(os.path.join(three_band_path, file_name))
    image_3 = np.transpose(image_3, (1, 2, 0))
    image_3 = image_3 / 2047 * 255
    image_3 = np.array(image_3, dtype=np.uint8)
    H = image.shape[1]
    W = image.shape[2]

    x_max, y_min = extra_functions._get_xmax_ymin(image_id)

    predicted_mask = extra_functions.make_prediction_cropped(
        model,
        image,
        initial_size=(128, 128),
        final_size=(128 - 32, 128 - 32),
        num_masks=num_mask_channels,
        num_channels=num_channels)

    mask_to_draw = np.zeros((H, W, 3), np.uint8)
    for i in range(num_mask_channels):
        mask_to_draw[predicted_mask[i] >= threshold] = color[i + 1]
        #mask_to_draw[predicted_mask[i]<threshold] = (255,188,64)

    image_mask = cv2.addWeighted(image_3, 0.6, mask_to_draw, 0.4, 0)