def test_make_plot(color_space: str, image_channels: str, source_path: str,
                   reference_path: str) -> None:
    params = Params(
        {
            'color_space': color_space,
            'channels': image_channels,
            'match_proportion': 0.8,
            'src_path': source_path,
            'ref_path': reference_path
        }
    )
    converter = build_cs_converter(params.color_space)

    source = read_image(params.src_path)
    reference = read_image(params.ref_path)

    source = converter.convert(source)
    reference = converter.convert(reference)

    channels = tuple(int(c) for c in params.channels.split(','))
    hist_match = HistogramMatching(channels, params.match_proportion)
    result = hist_match(source, reference)

    file_name = os.path.join(TEST_DIR, 'histogram_matching_plot.png')
    images = hm_plot.Images(source, reference, result)
    hm_plot.make_plot(file_name, images, converter, params.color_space,
                      params.channels)

    assert os.path.exists(file_name) is True

    os.remove(file_name)
def test_read_image() -> None:
    expected = np.asarray(Image.open(MUNICH_1_PATH)).astype(
        np.float32) / MAX_VALUE_8_BIT
    result = read_image(MUNICH_1_PATH)
    np.testing.assert_array_equal(result, expected)

    with pytest.raises(ValueError):
        read_image('no_image.png')
def test_apply_images(source_path: str, reference_path: str,
                      feature_dist_matching: FeatureDistMatching) -> \
        None:
    source = read_image(source_path)
    reference = read_image(reference_path)
    result = feature_dist_matching._apply(source, reference)
    assert result.shape == source.shape
    assert np.max(result) <= 1.
    assert 0.1 < np.mean(result) < 0.9
    assert np.min(result) >= 0.
    assert result.dtype == np.float32
    with np.testing.assert_raises(AssertionError):
        np.testing.assert_array_equal(result, source)
    with np.testing.assert_raises(AssertionError):
        np.testing.assert_array_equal(result, reference)
def test_image_histogram_gray() -> None:
    # pylint: disable=protected-access (W0212)
    img = read_image(MUNICH_1_GRAY_PATH)
    gray_hist = hm_plot._image_histogram_gray(img)

    expected_hist = np.histogram(img[:, :, 0], bins=hm_plot._BINS,
                                 range=hm_plot._HIST_RANGE)[0]
    assert gray_hist.name == hm_plot._GRAY
    np.testing.assert_array_equal(gray_hist.hist, expected_hist)
def test_cdf() -> None:
    # pylint: disable=protected-access (W0212)
    img = read_image(MUNICH_1_PATH)
    expected_values, counts = np.unique(img, return_counts=True)
    expected_cdf = np.cumsum(counts).astype(float) / img.size

    values, cdf = hm_plot._cdf(img)

    np.testing.assert_array_equal(values, expected_values)
    np.testing.assert_array_equal(cdf, expected_cdf)
def test_image_histogram_rgb() -> None:
    # pylint: disable=protected-access (W0212)
    img = read_image(MUNICH_1_PATH)
    hist = hm_plot._image_histogram_rgb(img)

    assert len(hist) == img.shape[-1]

    for channel in range(img.shape[-1]):
        expected_hist = np.histogram(img[:, :, channel], bins=hm_plot._BINS,
                                     range=hm_plot._HIST_RANGE)[0]

        assert hist[channel].name == hm_plot._HIST_RGB_COLORS[channel]
        np.testing.assert_array_equal(hist[channel].hist, expected_hist)
def test_read_image_gray() -> None:
    expected = np.asarray(Image.open(MUNICH_1_GRAY_PATH))[:, :, np.newaxis]
    expected = expected.astype(np.float32) / MAX_VALUE_8_BIT
    result = read_image(MUNICH_1_GRAY_PATH)
    np.testing.assert_array_equal(result, expected)
示例#8
0
def test_color_check_fail(color_space: str, source: str,
                          reference: str) -> None:
    source_image = read_image(source)
    reference_image = read_image(reference)
    with pytest.raises(ValueError):
        app.color_check(color_space, source_image, reference_image)