-
-
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
fix rotating for ellipse fit #2482
Conversation
55128a0
to
36a1614
Compare
skimage/measure/fit.py
Outdated
try: | ||
M = np.linalg.inv(C1).dot( | ||
S1 - np.dot(S2, np.linalg.inv(S3)).dot(S2.T)) | ||
except: # LinAlgError: Singular matrix |
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.
Please, be more strict on the exception you catch. Otherwise, you'll catch everything and errors can't be detected.
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.
Could you had a test that make sure that the exception will be raised and the final behavior is correct?
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.
well, the are two points, it anything happens during slowing this matrix multiplication, goes to not proper ellipse fitting and then the estimate fails anyway... second, I found this instability while testing ransac on real data so isolating the special case is possible but not common... :)
skimage/measure/fit.py
Outdated
@@ -515,7 +528,11 @@ def estimate(self, data): | |||
C1 = np.array([[0., 0., 2.], [0., -1., 0.], [2., 0., 0.]]) | |||
|
|||
# Reduced scatter matrix [eqn. 29] |
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.
move this comment after the try statement.
Has the bug been introduced in your last patch? namely commit d07592c |
excuse me, not sure what you mean by have been introduced in.. |
36a1614
to
3cb694c
Compare
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.
@Borda thanks for the fix! I've made some minor comments, should be quick to address!
skimage/measure/fit.py
Outdated
xc, yc, a, b, theta = params | ||
if isinstance(theta, complex): | ||
theta = np.real(theta) |
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.
I just saw that np.real
returns a 0-dimensional array. Do we want to cast to float? And do we want to do this anyway? It might be faster to pipe all values through float(np.real(theta))
than it is to check first. Thoughts?
skimage/measure/fit.py
Outdated
------- | ||
|
||
>>> xy = EllipseModel().predict_xy(np.linspace(0, 2 * np.pi, 25), | ||
... params=(10, 15, 4, 8, np.deg2rad(30))) |
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.
Minor: fix indent to match open paren
f9a170e
to
d60ebe5
Compare
skimage/measure/fit.py
Outdated
@@ -470,6 +470,19 @@ class EllipseModel(BaseModel): | |||
Ellipse model parameters in the following order `xc`, `yc`, `a`, `b`, | |||
`theta`. | |||
|
|||
Example |
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.
Examples
I looked at the history, the answer to my question is yes. So we should merge it for 0.13. |
d60ebe5
to
4d6f110
Compare
Codecov Report
@@ Coverage Diff @@
## master #2482 +/- ##
==========================================
+ Coverage 90.74% 90.76% +0.01%
==========================================
Files 304 304
Lines 21665 21678 +13
Branches 1867 1870 +3
==========================================
+ Hits 19660 19676 +16
+ Misses 1662 1661 -1
+ Partials 343 341 -2
Continue to review full report at Codecov.
|
skimage/measure/fit.py
Outdated
@@ -470,6 +470,19 @@ class EllipseModel(BaseModel): | |||
Ellipse model parameters in the following order `xc`, `yc`, `a`, `b`, | |||
`theta`. | |||
|
|||
Examples | |||
------- |
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.
Travis is unhappy about this docstring — I'm not sure if it's because there is a missing -
at the end to make the dashes' width equal to that of "Examples".
* fix crashes * add doctest example * update coverage * update review * update complex
4d6f110
to
d61e810
Compare
Good work, thanks! |
Description
fixing issue with estimated orientation, the equation was not implemented properly
Checklist
References
http://mathworld.wolfram.com/Ellipse.html#eqn23