Skip to content

Geometry Transforms: avoid division by zero & some degenerate cases#3926

Merged
stefanv merged 1 commit intoscikit-image:masterfrom
cv3d:transform/divideByZeroFix
May 27, 2019
Merged

Geometry Transforms: avoid division by zero & some degenerate cases#3926
stefanv merged 1 commit intoscikit-image:masterfrom
cv3d:transform/divideByZeroFix

Conversation

@cv3d
Copy link
Copy Markdown
Contributor

@cv3d cv3d commented May 23, 2019

Description

Minor update to avoid returning nans due to division by zeros & some degenerate cases

Checklist

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented May 23, 2019

Hello @cv3d! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-27 11:24:05 UTC

@cv3d cv3d force-pushed the transform/divideByZeroFix branch from 9d60ab1 to 9a9297c Compare May 23, 2019 13:56
@stefanv
Copy link
Copy Markdown
Member

stefanv commented May 23, 2019

Hey, @cv3d, thank you for submitting this PR.

Could you please expand on the problem you ran into, and why this is the correct fix?

@cv3d
Copy link
Copy Markdown
Contributor Author

cv3d commented May 23, 2019

Hi @stefanv. I am using these geometry transforms in a RANSAC iteration for model estimation, where some degenerative cases might be the cause of such errors.

The basic idea of this PR is to return some numerical values (even if they are very large) rather than NaNs, which might break the user code.

@jni
Copy link
Copy Markdown
Member

jni commented May 26, 2019

@cv3d I think we would like some comments around those lines to explain their purpose, as well as a test case that would fail without the fixes (so that if anyone changes the logic or the algorithm in the future, the new algorithm still has the same stability).

@cv3d cv3d force-pushed the transform/divideByZeroFix branch from 9a9297c to b8e89f4 Compare May 26, 2019 13:29
@cv3d cv3d changed the title Geometry Transforms: avoid division by zero Geometry Transforms: avoid division by zero & some degenerate cases May 26, 2019
@cv3d cv3d force-pushed the transform/divideByZeroFix branch from b8e89f4 to 0414efb Compare May 26, 2019 13:49
Copy link
Copy Markdown
Member

@jni jni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I just verified that these tests fail on master. Personally I would like more detail. For example,

  • in # avoid division by zero, instead write "below, we will divide by the last dimension of the homogeneous coordinate matrix. In order to avoid division by zero, we replace exact zeros in this column with a very small number."
  • in # is it a degenerate case?, for example, "if the last element of the vector corresponding to the smallest singular value is close to zero, this implies a degenerate case because..."

In the tests, you could add notes about why the tests are like this: instead of "either indicate a degenerate case, or return a transform. Prior to gh-3926, under these circumstances, a transform could be returned with nan values."

 - avoid division by zero
 - avoid some degenerate cases
@cv3d cv3d force-pushed the transform/divideByZeroFix branch from 0414efb to 97159d8 Compare May 27, 2019 11:24
@jni
Copy link
Copy Markdown
Member

jni commented May 27, 2019

@cv3d thanks for the update! Looks great!

@scikit-image/core imho this is merge-ready!

@stefanv stefanv merged commit 254b141 into scikit-image:master May 27, 2019
@stefanv
Copy link
Copy Markdown
Member

stefanv commented May 27, 2019

Thanks, @cv3d!

@cv3d cv3d deleted the transform/divideByZeroFix branch May 27, 2019 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants