Beispiel #1
0
def test_tile():
    n = 128
    images = []

    height, width = 16, 16
    for i in range(n):
        color = hsv_to_rgb(random.random(), 1, 1)
        image = np.zeros((3, 16, 16))
        for c in range(len(color)):
            image[c] = color[c]
        images.append(image)

    number = 20
    tiled = tile(images, columns_must_be_multiple_of=number)

    rows = tiled.shape[1] // height
    cols = tiled.shape[2] // width
    assert cols % number == 0
    for r in range(rows):
        for c in range(cols):
            idx = cols*r + c
            ri = r*height
            ci = c*width
            subimage = tiled[:, ri:ri+height, ci:ci+height]
            if idx < len(images):
                np.testing.assert_allclose(subimage, images[idx])

    fig = plt.figure()
    h_w_rgb = np.zeros((tiled.shape[1], tiled.shape[2], tiled.shape[0]))
    for i in range(3):
        h_w_rgb[:, :, i] = tiled[i]
    plt.imshow(h_w_rgb)
    plt_save_and_maybe_show("test_tile.png")
    plt.close(fig)
Beispiel #2
0
def visualise_tiles(images, show=True):
    """

    """
    tiled_fakes = tile(images)
    plt_imshow(tiled_fakes)
    plt.grid(False)
    plt.axis("off")
    if show:
        plt.show()
Beispiel #3
0
def zip_visualise_tiles(*arrs, show=True):
    import matplotlib.pyplot as plt
    assert len(arrs) >= 2
    length = len(arrs[0])
    for a in arrs:
        assert len(a) == length, "all input arrays must have the same size"
    tiles = []
    for i in range(length):
        for a in arrs:
            tiles.append(a[i])

    tiled = tile(tiles, columns_must_be_multiple_of=len(arrs))
    assert len(tiled) == 1, "currently only grayscale image are supported"
    plt.imshow(tiled[0], cmap='gray')
    if show:
        plt.show()
Beispiel #4
0
def zip_visualise_tiles(*arrs, show=True):
    import matplotlib.pyplot as plt
    assert len(arrs) >= 2
    length = len(arrs[0])
    for a in arrs:
        assert len(a) == length, "all input arrays must have the same size"
    tiles = []
    for i in range(length):
        for a in arrs:
            tiles.append(a[i])

    tiled = tile(tiles, columns_must_be_multiple_of=len(arrs))
    assert len(tiled) == 1, "currently only grayscale image are supported"
    plt.imshow(tiled[0], cmap='gray')
    if show:
        plt.show()