FIX add missing min_size parameter, add regression test.

This commit is contained in:
Andreas Mueller
2013-10-20 15:15:36 -07:00
parent 0bf06fbbc2
commit 57e37352cb
2 changed files with 21 additions and 2 deletions
+1 -2
View File
@@ -43,10 +43,9 @@ def felzenszwalb(image, scale=1, sigma=0.8, min_size=20):
Huttenlocher, D.P. International Journal of Computer Vision, 2004
"""
#image = img_as_float(image)
if image.ndim == 2:
# assume single channel image
return _felzenszwalb_grey(image, scale=scale, sigma=sigma)
return _felzenszwalb_grey(image, scale=scale, sigma=sigma, min_size=min_size)
elif image.ndim != 3:
raise ValueError("Felzenswalb segmentation can only operate on RGB and"
@@ -1,7 +1,9 @@
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
from skimage import data
def test_grey():
@@ -18,6 +20,24 @@ def test_grey():
hist = np.histogram(img[seg == i], bins=[0, 0.1, 0.3, 0.5, 1])[0]
assert_greater(hist[i], 40)
def test_minsize():
# single-channel:
img = data.coins()[20:168,0:128]
for min_size in np.arange(10, 100, 10):
segments = felzenszwalb(img, min_size=min_size, sigma=3)
counts = np.bincount(segments.ravel())
# actually want to test greater or equal.
assert_greater(counts.min() + 1, min_size)
# multi-channel:
coffee = data.coffee()[::4, ::4]
for min_size in np.arange(10, 100, 10):
segments = felzenszwalb(coffee, min_size=min_size, sigma=3)
counts = np.bincount(segments.ravel())
# actually want to test greater or equal.
# the construction doesn't guarantee min_size is respected
# after intersecting the sementations for the colors
assert_greater(np.mean(counts) + 1, min_size)
def test_color():
# very weak tests. This algorithm is pretty unstable.