mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-10 20:36:53 +08:00
Merge pull request #2083 from jmetz/regionprops_centroid3d
Updated centroid to use coords - works in 3d
This commit is contained in:
@@ -115,17 +115,14 @@ class _RegionProperties(object):
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
A tuple of the bounding box's start coordinates for each dimension,
|
||||
A tuple of the bounding box's start coordinates for each dimension,
|
||||
followed by the end coordinates for each dimension
|
||||
"""
|
||||
return tuple([self._slice[i].start for i in range(self._ndim)] +
|
||||
[self._slice[i].stop for i in range(self._ndim)])
|
||||
|
||||
def centroid(self):
|
||||
centroid_coords = self.local_centroid
|
||||
return tuple(centroid_coords +
|
||||
np.array([self._slice[i].start
|
||||
for i in range(self._ndim)]))
|
||||
return tuple(self.coords.mean(axis=0))
|
||||
|
||||
@only2d
|
||||
def convex_area(self):
|
||||
|
||||
@@ -24,7 +24,7 @@ INTENSITY_SAMPLE[1, 9:11] = 2
|
||||
|
||||
SAMPLE_3D = np.zeros((6, 6, 6), dtype=np.uint8)
|
||||
SAMPLE_3D[1:3, 1:3, 1:3] = 1
|
||||
SAMPLE_3D[3, 2, 2] = 1
|
||||
SAMPLE_3D[3, 2, 2] = 1
|
||||
INTENSITY_SAMPLE_3D = SAMPLE_3D.copy()
|
||||
|
||||
def test_all_props():
|
||||
@@ -97,6 +97,12 @@ def test_centroid():
|
||||
assert_array_almost_equal(centroid, (5.66666666666666, 9.444444444444444))
|
||||
|
||||
|
||||
def test_centroid_3d():
|
||||
centroid = regionprops(SAMPLE_3D)[0].centroid
|
||||
# determined by mean along axis 1 of SAMPLE_3D.nonzero()
|
||||
assert_array_almost_equal(centroid, (1.66666667, 1.55555556, 1.55555556))
|
||||
|
||||
|
||||
def test_convex_area():
|
||||
area = regionprops(SAMPLE)[0].convex_area
|
||||
# determined with MATLAB
|
||||
|
||||
Reference in New Issue
Block a user