ENH: add bbox_area

This commit is contained in:
François Boulogne
2016-07-14 16:19:20 +02:00
parent f7a0ee8ea4
commit 4d233442f7
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -21,6 +21,7 @@ STREL_26_3D = np.ones((3, 3, 3), dtype=np.uint8)
PROPS = {
'Area': 'area',
'BoundingBox': 'bbox',
'BoundingBoxArea': 'bbox_area',
'CentralMoments': 'moments_central',
'Centroid': 'centroid',
'ConvexArea': 'convex_area',
@@ -121,6 +122,9 @@ class _RegionProperties(object):
return tuple([self._slice[i].start for i in range(self._ndim)] +
[self._slice[i].stop for i in range(self._ndim)])
def bbox_area(self):
return self._label_image.size
def centroid(self):
return tuple(self.coords.mean(axis=0))
@@ -374,6 +378,8 @@ def regionprops(label_image, intensity_image=None, cache=True):
Bounding box ``(min_row, min_col, max_row, max_col)``.
Pixels belonging to the bounding box are in the half-open interval
``[min_row; max_row)`` and ``[min_col; max_col)``.
**bbox_area** : int
Number of pixels of bounding box.
**centroid** : array
Centroid coordinate tuple ``(row, col)``.
**convex_area** : int
@@ -77,6 +77,9 @@ def test_bbox():
bbox = regionprops(SAMPLE_3D)[0].bbox
assert_array_almost_equal(bbox, (1, 1, 1, 4, 3, 3))
def test_bbox_area():
bbox_area = regionprops(SAMPLE)[0].bbox_area
assert_array_almost_equal(bbox_area, SAMPLE.shape[0] * SAMPLE.shape[1])
def test_moments_central():
mu = regionprops(SAMPLE)[0].moments_central