-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign error fix in measure.regionprops for orientations of 45 degrees #6836
Sign error fix in measure.regionprops for orientations of 45 degrees #6836
Conversation
Nice work man. I was about to create a PR for same. |
thanks @jakeMartin1234! It looks like a test needs updating: _______________________________ test_orientation _______________________________
def test_orientation():
orient = regionprops(SAMPLE)[0].orientation
# determined with MATLAB
target_orient = -1.4663278802756865
assert_almost_equal(orient, target_orient)
orient = regionprops(SAMPLE, spacing=(2, 2))[0].orientation
assert_almost_equal(orient, target_orient)
# test diagonal regions
diag = np.eye(10, dtype=int)
orient_diag = regionprops(diag)[0].orientation
> assert_almost_equal(orient_diag, -math.pi / 4)
/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/skimage/measure/tests/test_regionprops.py:648:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (0.7853981633974483, -0.7853981633974483), kwds = {}
@wraps(func)
def inner(*args, **kwds):
with self._recreate_cm():
> return func(*args, **kwds)
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 0.7853981633974483
E DESIRED: -0.7853981633974483 I'd also like it if you could add an extra test: copy image over from #6815, then do something like: def test_orientation_continuity():
props = regionprops(image)
orientations = [prop.orientation for prop in props]
np.testing.assert_allclose(orientations, orientations[1], rtol=0, atol=0.08) |
@jni I just updated the test. Are you saying that I should copy over the image and store it in the repository then load it into the python file or copy over the arrays that that represent the images in #6815? If I need to store the image in the repository, where should I store it? Would be great if you could let me know so that I can add the test to my branch. |
You can just copy the code from the issue into the test function: def test_orientation_continuity():
# nearly diagonal array
arr1 = np.array([[0, 0, 1, 1],[0, 0, 1, 0],[0, 1, 0, 0],[1, 0, 0, 0]])
# diagonal array
arr2 = np.array([[0, 0, 0, 2],[0, 0, 2, 0],[0, 2, 0, 0],[2, 0, 0, 0]])
# nearly diagonal array
arr3 = np.array([[0, 0, 0, 3],[0, 0, 3, 3],[0, 3, 0, 0],[3, 0, 0, 0]])
image = np.hstack((arr1,arr2,arr3))
props = regionprops(image)
orientations = [prop.orientation for prop in props]
np.testing.assert_allclose(orientations, orientations[1], rtol=0, atol=0.08) |
Remember to push any additional commits to your branch so we can see them here! 😅 |
Hi @jni, I just pushed the new changes to the test file. I added a few more checks in the test_orientation_continuity(). Let me know if you think anything else needs changing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 😍
…cikit-image#6836) * fixed sign error for PI/4 and -PI/4 * fixed orientation test and added continuity test
Description
Fixed a sign error in the orientation property in measure.regionprops. The preset values for the orientations PI/4 and -PI/4 needed to be switched. This probably dates from switching regionprops over from xy coordinates to rc coordinates.
Closes #6815
Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.example, to backport to v0.19.x after merging, add the following in a PR
comment:
@meeseeksdev backport to v0.19.x
run-benchmark
label. To rerun, the labelcan be removed and then added again. The benchmark output can be checked in
the "Actions" tab.