extend draw.ellipse by orientation#2366
Conversation
|
@sciunto how can I find some more details why the checks failed? |
|
@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. |
JDWarner
left a comment
There was a problem hiding this comment.
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.
skimage/draw/draw.py
Outdated
| 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) |
There was a problem hiding this comment.
Specify that this is in radians, relative to the column (c) axis.
skimage/draw/draw.py
Outdated
| The ellipse equation: | ||
| ``((x * cos(alpha) + y * sin(alpha)) / xradius) ** 2 | ||
| + ((x * sin(alpha) + y * cos(alpha)) / yradius) ** 2 = 1`` | ||
|
|
There was a problem hiding this comment.
Please place this info in a new Notes section at the bottom of the docstring.
skimage/draw/draw.py
Outdated
|
|
||
|
|
||
| def ellipse(r, c, yradius, xradius, shape=None): | ||
| def ellipse(r, c, yradius, xradius, shape=None, orientation=0.): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Also, from an API standpoint I think I prefer rotation to orientation.
There was a problem hiding this comment.
yradius and xradius are already renamed in master branch.
@Borda please, do a rebase.
There was a problem hiding this comment.
@soupault I made pull in master (but it says it is up-to-date) and rebase master nothing changed.
There was a problem hiding this comment.
@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.
skimage/draw/draw.py
Outdated
| """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 |
There was a problem hiding this comment.
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.
skimage/draw/draw.py
Outdated
| :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 |
There was a problem hiding this comment.
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.
skimage/draw/draw.py
Outdated
| 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, |
There was a problem hiding this comment.
Please use the proper plural radii throughout.
Conflicts: skimage/draw/draw.py * update according PR comments * add unity test for multiple rotations
* add unity test for multiple rotations
|
Appveyor doesn't build the doc, so it passes. Check your example, the problem is in there. |
|
I see, the fail comes at line 38, which was |
| [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) |
There was a problem hiding this comment.
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.
|
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. |
skimage/draw/draw.py
Outdated
| Notes | ||
| ----- | ||
| The ellipse equation: | ||
| ``((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 |
There was a problem hiding this comment.
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).
…t-image into add_ellipse_rotation Conflicts: skimage/draw/draw.py
skimage/draw/draw.py
Outdated
| ----- | ||
| The ellipse equation:: | ||
|
|
||
| ((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 |
There was a problem hiding this comment.
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
Current coverage is 90.64% (diff: 100%)@@ 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
|
|
@JDWarner Are you fine with changes according your review? :) |
|
Looks good now - thanks for your contribution, @Borda, and sorry for the delay! |
Description
extension of an ellipse to have also parameter orientation as well as ellipse_perimeter
reflecting a "issue" #2135
Checklist
./doc/examples(new features only)[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 # ]