Raise error for non 2-D images

This commit is contained in:
Johannes Schönberger
2013-10-02 14:14:29 +02:00
parent c1ea012c9b
commit d7824000fe
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -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)