Exemple #1
0
def test_image_widget():
    # png works
    image = Image(value=Path(__file__).parent / "_test.png")
    assert isinstance(image._image, _mpl_image.Image)
    assert isinstance(image.image_data, np.ndarray)
    assert isinstance(image.image_rgba, np.ndarray)
    assert image.image_data.shape == (200, 232, 3)
    assert image.image_rgba.shape == (200, 232, 4)

    prev = image.image_data.copy()
    # jpg works works
    image.value = Path(__file__).parent / "_test.jpg"
    # png and jpg different enough
    assert not np.allclose(image.image_data, prev)
    assert image.image_data.shape == (200, 232, 3)
    assert image.image_rgba.shape == (200, 232, 4)

    # 2D float
    image.value = np.random.rand(64, 64)
    assert image.image_data.shape == (64, 64)
    assert image.image_rgba.shape == (64, 64, 4)

    # 2D uint8
    image.value = np.random.randint(0, 255, (60, 60)).astype("uint8")
    assert image.image_data.shape == (60, 60)
    assert image.image_rgba.shape == (60, 60, 4)

    # RGBA float
    image.value = np.random.rand(60, 60, 4).astype("float")
    assert image.image_data.shape == (60, 60, 4)
    assert image.image_rgba.shape == (60, 60, 4)
Exemple #2
0
def test_clim():

    # 2D uint8
    image = Image()
    image.value = np.random.rand(60, 60)
    rendered = image.image_rgba
    assert isinstance(rendered, np.ndarray)
    assert rendered.shape == (60, 60, 4)
    image.set_clim(0.5, 0.7)
    rendered2 = image.image_rgba
    assert not np.allclose(rendered, rendered2)
    assert image.get_clim() == (0.5, 0.7)