mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-03 09:28:38 +08:00
f2d5b109e9
Fix tests to work with nose < 1.1.3. Compatibility functions borrowed from scikit-learn.
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import numpy as np
|
|
from numpy.testing import assert_equal, assert_array_equal
|
|
from skimage._shared.testing import assert_greater
|
|
from skimage.segmentation import felzenszwalb
|
|
|
|
|
|
def test_grey():
|
|
# very weak tests. This algorithm is pretty unstable.
|
|
img = np.zeros((20, 21))
|
|
img[:10, 10:] = 0.2
|
|
img[10:, :10] = 0.4
|
|
img[10:, 10:] = 0.6
|
|
seg = felzenszwalb(img, sigma=0)
|
|
# we expect 4 segments:
|
|
assert_equal(len(np.unique(seg)), 4)
|
|
# that mostly respect the 4 regions:
|
|
for i in range(4):
|
|
hist = np.histogram(img[seg == i], bins=[0, 0.1, 0.3, 0.5, 1])[0]
|
|
assert_greater(hist[i], 40)
|
|
|
|
|
|
def test_color():
|
|
# very weak tests. This algorithm is pretty unstable.
|
|
img = np.zeros((20, 21, 3))
|
|
img[:10, :10, 0] = 1
|
|
img[10:, :10, 1] = 1
|
|
img[10:, 10:, 2] = 1
|
|
seg = felzenszwalb(img, sigma=0)
|
|
# we expect 4 segments:
|
|
assert_equal(len(np.unique(seg)), 4)
|
|
assert_array_equal(seg[:10, :10], 0)
|
|
assert_array_equal(seg[10:, :10], 2)
|
|
assert_array_equal(seg[:10, 10:], 1)
|
|
assert_array_equal(seg[10:, 10:], 3)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from numpy import testing
|
|
testing.run_module_suite()
|