mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
Merge pull request #238 from ahojnnes/regionprops-orientation
Regionprops orientation bugfix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# coding: utf-8
|
||||
from math import sqrt, atan, pi as PI
|
||||
from math import sqrt, atan2, pi as PI
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
|
||||
@@ -301,7 +301,7 @@ def regionprops(label_image, properties=['Area', 'Centroid'],
|
||||
if a - c == 0:
|
||||
obj_props['Orientation'] = PI / 2
|
||||
else:
|
||||
obj_props['Orientation'] = - 0.5 * atan(2 * b / (a - c))
|
||||
obj_props['Orientation'] = - 0.5 * atan2(2 * b, (a - c))
|
||||
|
||||
if 'Perimeter' in properties:
|
||||
obj_props['Perimeter'] = perimeter(array, 4)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from numpy.testing import assert_array_equal, assert_almost_equal, \
|
||||
assert_array_almost_equal
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
from skimage.measure import regionprops
|
||||
|
||||
@@ -193,6 +194,9 @@ def test_orientation():
|
||||
orientation = regionprops(SAMPLE, ['Orientation'])[0]['Orientation']
|
||||
# determined with MATLAB
|
||||
assert_almost_equal(orientation, 0.10446844651921)
|
||||
# test correct quadrant determination
|
||||
orientation2 = regionprops(SAMPLE.T, ['Orientation'])[0]['Orientation']
|
||||
assert_almost_equal(orientation2, math.pi / 2 - orientation)
|
||||
|
||||
def test_perimeter():
|
||||
perimeter = regionprops(SAMPLE, ['Perimeter'])[0]['Perimeter']
|
||||
|
||||
Reference in New Issue
Block a user