def mirror_borders(tile, image):
    """ Mirror the border values for the tiles extending the image borders. """
    # lower X-edge
    diff = max(0, image.offset.x - tile.offset.x)
    tile.data[:, :diff, :] = tile.data[:, (2*diff - 1):(diff - 1):-1, :]

    # upper X-edge
    size = tile.size.x
    diff = max(0, (tile.offset.x + size) - (image.offset.x + image.size.x))
    tile.data[:, (size - 1):(size - diff - 1):-1, :] = (
        tile.data[:, (size - 2*diff):(size - diff), :]
    )

    # lower Y-edge
    diff = max(0, image.offset.y - tile.offset.y)
    tile.data[:diff, :, :] = tile.data[(2*diff - 1):(diff - 1):-1, :, :]

    # upper Y-edge
    size = tile.size.y
    diff = max(0, (tile.offset.y + size) - (image.offset.y + image.size.y))
    tile.data[(size - 1):(size - diff - 1):-1, :, :] = (
        tile.data[(size - 2*diff):(size - diff), :, :]
    )
    return tile