Skip to content

extend draw.ellipse by orientation#2366

Merged
JDWarner merged 12 commits intoscikit-image:masterfrom
Borda:add_ellipse_rotation
Dec 7, 2016
Merged

extend draw.ellipse by orientation#2366
JDWarner merged 12 commits intoscikit-image:masterfrom
Borda:add_ellipse_rotation

Conversation

@Borda
Copy link
Copy Markdown
Contributor

@Borda Borda commented Nov 3, 2016

Description

extension of an ellipse to have also parameter orientation as well as ellipse_perimeter
reflecting a "issue" #2135

Checklist

[For detailed information on these and other aspects see scikit-image contribution guidelines]

References

[If this is a bug-fix or enhancement, it closes issue # ]

@Borda Borda changed the title init task extend draw.ellipse by orientation Nov 3, 2016
@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Nov 4, 2016

@sciunto how can I find some more details why the checks failed?

@alexdesiqueira
Copy link
Copy Markdown
Member

alexdesiqueira commented Nov 4, 2016

Hi @Borda, I treated that issue on #2352. Where do these PRs differ?
Thanks!

@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Nov 5, 2016

@alexandrejaguar in you case putting orientation as fifth parameter, may break compatibility for some previous calling and you use orientation in degrees wile other functions like draw.ellipse_perimeter already use radians.

Copy link
Copy Markdown
Contributor

@JDWarner JDWarner left a comment

Choose a reason for hiding this comment

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

I approve the idea and the implementation looks good. Before approval, there are some stylistic changes needed noted below.

You've added a doctest for this functionality, but I would also like a unit test or two added to the test suite. Our in-depth CI testing runs all the doctests, but a typical person testing the package does not (with make test or similar). Unit tests are quite simple; look in the tests subdirectory and follow the form there.

Testing a few orientations and then verifying exactly the same results with rotation plus/minus some multiple of 2*pi would be a good starting point.

coordinates. This is useful for ellipses which exceed the image size.
By default the full extent of the ellipse are used.
orientation : float, optional (default 0.)
Set the ellipse orientation (rotation)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Specify that this is in radians, relative to the column (c) axis.

The ellipse equation:
``((x * cos(alpha) + y * sin(alpha)) / xradius) ** 2
+ ((x * sin(alpha) + y * cos(alpha)) / yradius) ** 2 = 1``

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please place this info in a new Notes section at the bottom of the docstring.



def ellipse(r, c, yradius, xradius, shape=None):
def ellipse(r, c, yradius, xradius, shape=None, orientation=0.):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As these are not kwargs, renaming yradius -> rradius and xradius -> cradius should be done for consistency. It won't break anything. Also update the relevant part of the docstring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, from an API standpoint I think I prefer rotation to orientation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yradius and xradius are already renamed in master branch.
@Borda please, do a rebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@soupault I made pull in master (but it says it is up-to-date) and rebase master nothing changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Borda please, double check :). I'm pretty sure the latest signature is different - https://github.com/scikit-image/scikit-image/blob/master/skimage/draw/draw.py#L20.

"""Generate coordinates of points within ellipse bounded by shape."""
def _ellipse_in_shape(shape, center, radiuses, orientation=0.):
""" Generate coordinates of points within ellipse bounded by shape.
see: http://www.maa.org/external_archive/joma/Volume8/Kalman/General.html
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put the reference in a References section at the bottom of the docstring - look elsewhere in the package for the proper Sphinx formatting for this.

:param center: (float, float) position of center
:param radiuses: (float, float) size of the two half axis
:param orientation: float, orientation in radians
:return: [int], [int] coordinates of ellipse
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use NumPy documentation standards, e.g.,

"""
Parameters
----------
shape :  iterable of ints
    Shape of the input image.  Must be length 2.
center : iterable of floats
    (row, column) position of center (in what coordinates?  Presumably index coordinates?).
radii : iterable of floats
    Size of two half axes (for row and column, prior to orientation presumably?)
orientation : float, optional
    Rotation of the ellipse defined by the above, in radians, with respect to the column-axis.

Returns
-------
rows : iterable of ints
    Row coordinates representing values within the ellipse.
cols : iterable of ints
    Corresponding column coordinates representing values within the ellipse.
"""

or similar.

bounding_shape = lower_right - upper_left + 1

rr, cc = _ellipse_in_shape(bounding_shape, shifted_center, radiuses)
rr, cc = _ellipse_in_shape(bounding_shape, shifted_center, radiuses,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use the proper plural radii throughout.

@alexdesiqueira
Copy link
Copy Markdown
Member

alexdesiqueira commented Nov 5, 2016

@Borda using theta as degrees should be easy to solve. Also, shape is commonly the last argument according to other functions (respecting the API). @soupault @sciunto @JDWarner I submitted #2352 before this and no one checked that PR. Is there anything wrong?

@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Nov 8, 2016

May I ask what is going on with the "ERROR: Unexpected indentation." @soupault @JDWarner
the compilation on appveyor is fine but it crashes on travis-ci for the doc string...

@sciunto
Copy link
Copy Markdown
Member

sciunto commented Nov 9, 2016

Appveyor doesn't build the doc, so it passes. Check your example, the problem is in there.

@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Nov 9, 2016

I see, the fail comes at line 38, which was '.. rubric:: Notes', but it is the same as further '.. rubric:: Examples' so is there a list of possible rubrics?

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

>>> img = np.zeros((10, 12), dtype=np.uint8)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would remove the previous example in favor of your example, which is more general. One is enough I think and it has the advantage to keep the docstring as short as possible.

@sciunto
Copy link
Copy Markdown
Member

sciunto commented Nov 9, 2016

Just by eye inspection, I do not detect the problem... I need to test your commit. However, I left a little comment. To me, the section's names are fine.

Notes
-----
The ellipse equation:
``((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that the issue is probably here.
Please, check with the different formatting (https://github.com/scikit-image/scikit-image/blob/master/skimage/transform/_geometric.py#L302).

@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Nov 11, 2016

@sciunto @soupault Do you have any idea what is wrong with the doc string?
@JDWarner Do you agree with changes according review?

-----
The ellipse equation::

((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think Sphinx expects an indentation here. Try this:

    The ellipse equation::

        ((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 +
        ((x * sin(alpha) - y * cos(alpha)) / y_radius) ** 2 = 1

@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 14, 2016

Current coverage is 90.64% (diff: 100%)

Merging #2366 into master will decrease coverage by <.01%

@@             master      #2366   diff @@
==========================================
  Files           305        305          
  Lines         21587      21625    +38   
  Methods           0          0          
  Messages          0          0          
  Branches       1854       1858     +4   
==========================================
+ Hits          19568      19602    +34   
- Misses         1665       1668     +3   
- Partials        354        355     +1   

Powered by Codecov. Last update 86edbf0...d77abb9

@Borda
Copy link
Copy Markdown
Contributor Author

Borda commented Dec 7, 2016

@JDWarner Are you fine with changes according your review? :)

@JDWarner
Copy link
Copy Markdown
Contributor

JDWarner commented Dec 7, 2016

Looks good now - thanks for your contribution, @Borda, and sorry for the delay!

@JDWarner JDWarner merged commit 2659b3b into scikit-image:master Dec 7, 2016
@Borda Borda deleted the add_ellipse_rotation branch December 7, 2016 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⏩ type: Enhancement Improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants