mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 18:48:48 +08:00
BUG: Fix Orientation for diagonal regions in regionprops.
This commit is contained in:
@@ -124,7 +124,7 @@ def regionprops(label_image, properties=['Area', 'Centroid'],
|
||||
* Orientation : float
|
||||
Angle between the X-axis and the major axis of the ellipse that has
|
||||
the same second-moments as the region. Ranging from `-pi/2` to
|
||||
`-pi/2` in counter-clockwise direction.
|
||||
`pi/2` in counter-clockwise direction.
|
||||
* Perimeter : float
|
||||
Perimeter of object which approximates the contour as a line through
|
||||
the centers of border pixels using a 4-connectivity.
|
||||
@@ -299,7 +299,10 @@ def regionprops(label_image, properties=['Area', 'Centroid'],
|
||||
|
||||
if 'Orientation' in properties:
|
||||
if a - c == 0:
|
||||
obj_props['Orientation'] = PI / 2
|
||||
if b > 0:
|
||||
obj_props['Orientation'] = -PI / 4.
|
||||
else:
|
||||
obj_props['Orientation'] = PI / 4.
|
||||
else:
|
||||
obj_props['Orientation'] = - 0.5 * atan2(2 * b, (a - c))
|
||||
|
||||
|
||||
@@ -197,6 +197,15 @@ def test_orientation():
|
||||
# test correct quadrant determination
|
||||
orientation2 = regionprops(SAMPLE.T, ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation2, math.pi / 2 - orientation)
|
||||
# test diagonal regions
|
||||
orientation_diag = regionprops(np.eye(10, dtype=int), ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation_diag, -math.pi / 4)
|
||||
orientation_diag = regionprops(np.flipud(np.eye(10, dtype=int)), ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation_diag, math.pi / 4)
|
||||
orientation_diag = regionprops(np.fliplr(np.eye(10, dtype=int)), ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation_diag, math.pi / 4)
|
||||
orientation_diag = regionprops(np.fliplr(np.flipud(np.eye(10, dtype=int))), ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation_diag, -math.pi / 4)
|
||||
|
||||
def test_perimeter():
|
||||
perimeter = regionprops(SAMPLE, ['Perimeter'])[0]['Perimeter']
|
||||
|
||||
Reference in New Issue
Block a user