コード例 #1
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_normalize():
    im = cp.asarray([0, 255, 255], dtype=np.uint8)
    frequencies, bin_centers = exposure.histogram(im,
                                                  source_range="dtype",
                                                  normalize=False)
    expected = cp.zeros(256)
    expected[0] = 1
    expected[-1] = 2
    assert_array_equal(frequencies, expected)
    frequencies, bin_centers = exposure.histogram(im,
                                                  source_range="dtype",
                                                  normalize=True)
    expected /= 3.0
    assert_array_equal(frequencies, expected)
コード例 #2
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_all_negative_image():
    im = cp.asarray([-100, -1], dtype=np.int8)
    frequencies, bin_centers = exposure.histogram(im)
    assert_array_equal(bin_centers, cp.arange(-100, 0))
    assert frequencies[0] == 1
    assert frequencies[-1] == 1
    assert_array_equal(frequencies[1:-1], 0)
コード例 #3
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_peak_int_range_dtype():
    im = cp.asarray([10, 100], dtype=np.int8)
    frequencies, bin_centers = exposure.histogram(im, source_range="dtype")
    assert_array_equal(bin_centers, cp.arange(-128, 128))
    assert frequencies[128 + 10] == 1
    assert frequencies[128 + 100] == 1
    assert frequencies[128 + 101] == 0
    assert frequencies.shape == (256, )
コード例 #4
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_peak_float_out_of_range_dtype():
    im = cp.asarray([10, 100], dtype=np.float16)
    nbins = 10
    frequencies, bin_centers = exposure.histogram(im,
                                                  nbins=nbins,
                                                  source_range="dtype")
    assert_almost_equal(cp.min(bin_centers).get(), -0.9, 3)
    assert_almost_equal(cp.max(bin_centers).get(), 0.9, 3)
    assert len(bin_centers) == 10
コード例 #5
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_dask_histogram():
    pytest.importorskip("dask", reason="dask python library is not installed")
    import dask.array as da

    dask_array = da.from_array(cp.asarray([[0, 1], [1, 2]]), chunks=(1, 2))
    output_hist, output_bins = exposure.histogram(dask_array)
    expected_bins = [0, 1, 2]
    expected_hist = [1, 2, 1]
    assert cp.allclose(expected_bins, output_bins)
    assert cp.allclose(expected_hist, output_hist)
コード例 #6
0
def test_adapthist_color():
    """Test an RGB color uint16 image"""
    img = util.img_as_uint(data.astronaut())
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        hist, bin_centers = exposure.histogram(img)
        assert len(w) > 0
    adapted = exposure.equalize_adapthist(img, clip_limit=0.01)

    assert adapted.min() == 0
    assert adapted.max() == 1.0
    assert img.shape == adapted.shape
    full_scale = exposure.rescale_intensity(img)
    assert_almost_equal(float(peak_snr(full_scale, adapted)), 109.393, 1)
    assert_almost_equal(float(norm_brightness_err(full_scale, adapted)), 0.02,
                        2)
    return data, adapted
コード例 #7
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_peak_float_out_of_range_image():
    im = cp.asarray([10, 100], dtype=np.float16)
    frequencies, bin_centers = exposure.histogram(im, nbins=90)
    # offset values by 0.5 for float...
    assert_array_equal(bin_centers, cp.arange(10, 100) + 0.5)
コード例 #8
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_flat_int_range_dtype():
    im = cp.linspace(-128, 128, 256, dtype=np.int8)
    frequencies, bin_centers = exposure.histogram(im, source_range="dtype")
    assert_array_equal(bin_centers, cp.arange(-128, 128))
    assert frequencies.shape == (256, )
コード例 #9
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_int_range_image():
    im = cp.asarray([10, 100], dtype=np.int8)
    frequencies, bin_centers = exposure.histogram(im)
    assert len(bin_centers) == len(frequencies)
    assert bin_centers[0] == 10
    assert bin_centers[-1] == 100
コード例 #10
0
ファイル: test_exposure.py プロジェクト: MannyKayy/cupyimg
def test_wrong_source_range():
    im = cp.asarray([-1, 100], dtype=np.int8)
    with pytest.raises(ValueError):
        frequencies, bin_centers = exposure.histogram(im,
                                                      source_range="foobar")