Пример #1
0
def test_channels_size_mismatch(color_white, range_all):
    '''Test supplying channels with different dimensions'''

    input_channels = [{
        'image': np.array([[0, 0, 0]], dtype=np.uint16),
        'color': color_white,
        'min': range_all[0],
        'max': range_all[1]
    }, {
        'image': np.array([[0, 65535]], dtype=np.uint16),
        'color': color_white,
        'min': range_all[0],
        'max': range_all[1]
    }]

    with pytest.raises(ValueError):
        composite_channels(input_channels)
Пример #2
0
    def _render_tile(
        self,
        uuid,
        x,
        y,
        z,
        t,
        level,
        channels,
        gamma=1,
        codec="jpg",
        raw_format="tiff",
        tile_size=1024,
    ):
        # Prepare for blending
        args = [(uuid, x, y, z, t, channel["index"], level, raw_format)
                for channel in channels]

        # Fetch raw tiles in parallel
        tile_provider = S3TileProvider(
            bucket.split(":")[-1],
            missing_tile_callback=handle_missing_tile,
            cache_client=redis_client_raw,
            tile_size=tile_size,
        )
        try:
            images = pool.starmap(tile_provider.get_tile, args)
        finally:
            pass

        # Update channel dictionary with image data
        for channel, image in zip(channels, images):
            channel["image"] = image

        # Blend the raw tiles
        composite = render.composite_channels(channels, gamma=gamma)

        # Encode rendered image as JPG
        img = BytesIO()
        imagecodecs.imwrite(img, composite, codec=codec, level=85)
        img.seek(0)

        return img.read()
Пример #3
0
def test_channels_two_channel(u16_checkered_channel,
                              u16_checkered_channel_inverse, color_blue,
                              color_yellow, range_all):
    '''Test blending an image with two channels'''

    expected = np.array([
        [color_yellow, color_blue],
        [color_blue, color_yellow],
    ],
                        dtype=np.float32)

    result = composite_channels([{
        'image': u16_checkered_channel,
        'color': color_blue,
        'min': range_all[0],
        'max': range_all[1]
    }, {
        'image': u16_checkered_channel_inverse,
        'color': color_yellow,
        'min': range_all[0],
        'max': range_all[1]
    }])

    np.testing.assert_allclose(expected, result)
Пример #4
0
def test_channels_size_zero():
    '''Test supplying no channels'''

    with pytest.raises(ValueError):
        composite_channels([])