Exemple #1
0
def test_hdf5_loading_multimap() -> None:
    """
    Check that multimap returns correct image
    """
    image_header = io_util.load_image(f"{good_h5_path}|segmentation|0")
    seg_header = io_util.load_image(f"{good_h5_path}|segmentation|0|1")
    expected = image_header.image == 1
    assert np.array_equal(expected, seg_header.image)
Exemple #2
0
def test_hdf5_loading() -> None:
    """
    Check that when we access and invalid dataset we get a good exception
    """
    with pytest.raises(ValueError) as valueError:
        io_util.load_image(f"{good_h5_path}|doesnotexist|0|1")
    assert str(good_h5_path) in str(valueError.value)
    assert "doesnotexist" in str(valueError.value)
Exemple #3
0
def _test_load_images_from_channels(
        metadata: Any,
        image_channel: Any,
        ground_truth_channel: Any,
        mask_channel: Any) -> None:
    """
    Test if images are loaded as expected from channels
    """
    sample = io_util.load_images_from_dataset_source(
        PatientDatasetSource(
            metadata=metadata,
            image_channels=[image_channel] * 2,
            ground_truth_channels=[ground_truth_channel] * 4,
            mask_channel=mask_channel
        )
    )
    if image_channel:
        image_with_header = io_util.load_image(image_channel)
        assert list(sample.image.shape) == [2] + list(image_with_header.image.shape)
        assert all([np.array_equal(x, image_with_header.image) for x in sample.image])  # type: ignore
        if mask_channel:
            assert np.array_equal(sample.mask, image_with_header.image)
        if ground_truth_channel:
            assert list(sample.labels.shape) == [5] + list(image_with_header.image.shape)
            assert np.all(sample.labels[0] == 0) and np.all(sample.labels[1:] == 1)
def test_hdf5_loading_multimap_class_do_not_exists() -> None:
    """
    Check that multimap returns correct image if class does not exist
    """
    seg_header = io_util.load_image(
        f"{good_h5_path}|segmentation|0|555555555555")
    assert np.all(seg_header.image == 0)
Exemple #5
0
    def save_and_reload_image(
            data: np.array,  # type: ignore
            mode: str) -> None:
        path = test_output_dirs.root_dir / f"{mode}.png"
        image = Image.fromarray(data, mode=mode)
        image.save(path)

        scipy_image = imageio.imread(path).astype(np.float)
        assert scipy_image.dtype == np.float  # type: ignore
        assert np.array_equal(data, scipy_image)

        image_with_header = io_util.load_image(path)
        assert image_with_header.image.dtype == np.float  # type: ignore
        assert np.array_equal(data, image_with_header.image)