Exemplo n.º 1
0
def test_bimodal_multiotsu_hist():
    for name in ['camera', 'moon', 'coins', 'text', 'clock', 'page']:
        img = cp.array(getattr(data, name)())
        assert threshold_otsu(img) == threshold_multiotsu(img, 2)

    for name in ['chelsea', 'coffee', 'astronaut', 'rocket']:
        img = rgb2gray(cp.array(getattr(data, name)()))
        assert threshold_otsu(img) == threshold_multiotsu(img, 2)
Exemplo n.º 2
0
def test_multiotsu_output():
    image = cp.zeros((100, 100), dtype='int')
    coords = [(25, 25), (50, 50), (75, 75)]
    values = [64, 128, 192]
    for coor, val in zip(coords, values):
        rr, cc = disk(coor, 20)
        rr, cc = cp.asarray(rr), cp.asarray(cc)
        image[rr, cc] = val
    thresholds = [0, 64, 128]
    assert_array_equal(thresholds, threshold_multiotsu(image, classes=4))
Exemplo n.º 3
0
def test_check_multiotsu_results():
    # fmt: off
    image = 0.25 * cp.array([[0, 1, 2, 3, 4],
                             [0, 1, 2, 3, 4],
                             [0, 1, 2, 3, 4],
                             [0, 1, 2, 3, 4]])
    # fmt: on
    for idx in range(3, 6):
        thr_multi = threshold_multiotsu(image,
                                        classes=idx)
        assert len(thr_multi) == idx - 1
Exemplo n.º 4
0
def test_multiotsu_more_classes_then_values():
    img = cp.ones((10, 10), dtype=cp.uint8)
    with testing.raises(ValueError):
        threshold_multiotsu(img, classes=2)
    img[:, 3:] = 2
    with testing.raises(ValueError):
        threshold_multiotsu(img, classes=3)
    img[:, 6:] = 3
    with testing.raises(ValueError):
        threshold_multiotsu(img, classes=4)
Exemplo n.º 5
0
def test_multiotsu_astro_image():
    img = util.img_as_ubyte(astronautd)
    with expected_warnings(['grayscale']):
        assert_array_almost_equal(threshold_multiotsu(img), [58, 149])