mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-08 11:26:12 +08:00
Merge pull request #795 from amueller/fix_felsenszwalb_minsize
BUG: Felsenszwalb minsize parameter not passed on in single channel case
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -104,6 +104,8 @@ def _felzenszwalb_grey(image, double scale=1, sigma=0.8,
|
||||
seg0 = find_root(segments_p, edges_p[0])
|
||||
seg1 = find_root(segments_p, edges_p[1])
|
||||
edges_p += 2
|
||||
if seg0 == seg1:
|
||||
continue
|
||||
if segment_size[seg0] < min_size or segment_size[seg1] < min_size:
|
||||
join_trees(segments_p, seg0, seg1)
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user