mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 03:52:54 +08:00
Raise error for non 2-D images
This commit is contained in:
@@ -471,6 +471,11 @@ def regionprops(label_image, properties=None,
|
||||
>>> props[0]['centroid'] # centroid of first labelled object
|
||||
"""
|
||||
|
||||
label_image = np.squeeze(label_image)
|
||||
|
||||
if label_image.ndim != 2:
|
||||
raise TypeError('Only 2-D images supported.')
|
||||
|
||||
if properties is not None:
|
||||
warnings.warn('The ``properties`` argument is deprecated and is '
|
||||
'not needed any more as properties are '
|
||||
|
||||
@@ -34,6 +34,13 @@ def test_dtype():
|
||||
assert_raises(TypeError, regionprops, np.zeros((10, 10), dtype=np.double))
|
||||
|
||||
|
||||
def test_ndim():
|
||||
regionprops(np.zeros((10, 10), dtype=np.int))
|
||||
regionprops(np.zeros((10, 10, 1), dtype=np.int))
|
||||
regionprops(np.zeros((10, 10, 1, 1), dtype=np.int))
|
||||
assert_raises(TypeError, regionprops, np.zeros((10, 10, 2), dtype=np.int))
|
||||
|
||||
|
||||
def test_area():
|
||||
area = regionprops(SAMPLE)[0].area
|
||||
assert area == np.sum(SAMPLE)
|
||||
|
||||
Reference in New Issue
Block a user