Skip to content
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

Sorting the coordinates of draw.ellipse #7232

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions skimage/draw/_draw.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ def _ellipse_perimeter(Py_ssize_t r_o, Py_ssize_t c_o, Py_ssize_t r_radius,
rr.extend(rr_t)
cc.extend(cc_t)

# sorting on the basis of angle
rr = np.array(rr, dtype=np.intp)
cc = np.array(cc, dtype=np.intp)
angle = np.argsort(np.arctan2(cc-np.mean(cc),rr-np.mean(rr)))
rr = np.take(rr, angle, axis=0)
cc = np.take(cc, angle, axis=0)

Comment on lines +527 to +533
Copy link
Member

Choose a reason for hiding this comment

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

Hey @anamfatima1304, thanks for working on this! In case you are not aware, this fails because this file is written in Cython. Similar to C, the variables rr and cc were declared with cdef list rr = ... so you can't assign an array to them because it is a different type.

Instead I would propose that you move this snippet to the Python level in ellipse_perimeter.

if shape is not None:
return _coords_inside_image(np.array(rr, dtype=np.intp),
np.array(cc, dtype=np.intp), shape)
Expand Down