def test_bimodal_multiotsu_hist():
    for name in ['camera', 'moon', 'coins', 'text', 'clock', 'page']:
        img = getattr(data, name)()
        assert threshold_otsu(img) == threshold_multiotsu(img, 2)

    for name in ['chelsea', 'coffee', 'astronaut', 'rocket']:
        img = rgb2gray(getattr(data, name)())
        assert threshold_otsu(img) == threshold_multiotsu(img, 2)
Exemple #2
0
def test_multiotsu_hist_parameter():
    for classes in [2, 3, 4]:
        for name in ['camera', 'moon', 'coins', 'text', 'clock', 'page']:
            img = getattr(data, name)()
            sk_hist = histogram(img, nbins=256)
            #
            thresh_img = threshold_multiotsu(img, classes)
            thresh_sk_hist = threshold_multiotsu(classes=classes, hist=sk_hist)
            assert np.allclose(thresh_img, thresh_sk_hist)
Exemple #3
0
def test_multiotsu_output():
    image = np.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 = circle(coor[1], coor[0], 20)
        image[rr, cc] = val
    thresholds = [64, 128]
    assert np.array_equal(thresholds, threshold_multiotsu(image))

    image = color.rgb2gray(data.astronaut())
    assert_almost_equal(threshold_multiotsu(image, 2), 0.43945312)
def test_check_multiotsu_results():
    image = 0.25 * np.array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4],
                             [0, 1, 2, 3, 4]])

    for idx in range(3, 6):
        thr_multi = threshold_multiotsu(image, classes=idx)
        assert len(thr_multi) == idx - 1
def test_multiotsu_output():
    image = np.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)
        image[rr, cc] = val
    thresholds = [0, 64, 128]
    assert np.array_equal(thresholds, threshold_multiotsu(image, classes=4))
Exemple #6
0
def test_multiotsu_output():
    image = np.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 = circle(coor[1], coor[0], 20)
        image[rr, cc] = val
    t1, t2 = threshold_multiotsu(image)
    # since the image only contains values 64, 128, 192, and the image is
    # compared to the threshold with a strictly greater than check, thresholds
    # 64, 65, ..., 127 are all equivalent, and thresholds 128, 129, ..., 191
    # are all equivalent. The overly stringent check of t1 == 64 was causing
    # some 32-bit builds to fail. See e.g.
    # https://travis-ci.org/scikit-image/scikit-image-wheels/jobs/595911861#L3896-L3911
    assert t1 in range(64, 128)
    assert t2 in range(128, 192)

    image = color.rgb2gray(data.astronaut())
    assert_almost_equal(threshold_multiotsu(image, 2), 0.43945312)
def test_multiotsu_more_classes_then_values():
    img = np.ones((10, 10), dtype=np.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)
def test_multiotsu_astro_image():
    img = util.img_as_ubyte(data.astronaut())
    with expected_warnings(['grayscale']):
        assert_almost_equal(threshold_multiotsu(img), [58, 149])
def test_bimodal_multiotsu_hist():
    image = data.camera()
    thr_otsu = threshold_otsu(image)
    thr_multi = threshold_multiotsu(image, classes=2)
    assert thr_otsu == thr_multi
Exemple #10
0
def test_multiotsu_missing_img_and_hist():
    with pytest.raises(Exception):
        threshold_multiotsu()