mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 05:52:49 +08:00
Merge pull request #748 from ahojnnes/regionprops-dtype
- Fix for regionprops dtype error (#747) and additional tests. - Some docstring improvements.
This commit is contained in:
@@ -13,8 +13,8 @@ __all__ = ['regionprops']
|
||||
|
||||
STREL_4 = np.array([[0, 1, 0],
|
||||
[1, 1, 1],
|
||||
[0, 1, 0]])
|
||||
STREL_8 = np.ones((3, 3), 'int8')
|
||||
[0, 1, 0]], dtype=np.uint8)
|
||||
STREL_8 = np.ones((3, 3), dtype=np.uint8)
|
||||
PROPS = {
|
||||
'Area': 'area',
|
||||
'BoundingBox': 'bbox',
|
||||
@@ -470,8 +470,11 @@ def regionprops(label_image, properties=None,
|
||||
>>> props[0].centroid # centroid of first labelled object
|
||||
>>> props[0]['centroid'] # centroid of first labelled object
|
||||
"""
|
||||
if not np.issubdtype(label_image.dtype, 'int'):
|
||||
raise TypeError('Labelled image must be of integer dtype.')
|
||||
|
||||
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 '
|
||||
@@ -498,14 +501,14 @@ def perimeter(image, neighbourhood=4):
|
||||
Parameters
|
||||
----------
|
||||
image : array
|
||||
binary image
|
||||
Binary image.
|
||||
neighbourhood : 4 or 8, optional
|
||||
neighbourhood connectivity for border pixel determination, default 4
|
||||
Neighborhood connectivity for border pixel determination.
|
||||
|
||||
Returns
|
||||
-------
|
||||
perimeter : float
|
||||
total perimeter of all objects in binary image
|
||||
Total perimeter of all objects in binary image.
|
||||
|
||||
References
|
||||
----------
|
||||
@@ -521,7 +524,7 @@ def perimeter(image, neighbourhood=4):
|
||||
eroded_image = ndimage.binary_erosion(image, strel, border_value=0)
|
||||
border_image = image - eroded_image
|
||||
|
||||
perimeter_weights = np.zeros(50, float)
|
||||
perimeter_weights = np.zeros(50, dtype=np.double)
|
||||
perimeter_weights[[5, 7, 15, 17, 25, 27]] = 1
|
||||
perimeter_weights[[21, 33]] = sqrt(2)
|
||||
perimeter_weights[[13, 23]] = (1 + sqrt(2)) / 2
|
||||
|
||||
@@ -28,10 +28,19 @@ def test_all_props():
|
||||
regions[prop]
|
||||
|
||||
|
||||
def test_unsupported_dtype():
|
||||
def test_dtype():
|
||||
regionprops(np.zeros((10, 10), dtype=np.int))
|
||||
regionprops(np.zeros((10, 10), dtype=np.uint))
|
||||
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