-
-
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
behaviour of rectangle and polygon of skimage.draw to float inputs #4283
Comments
@ajkswamy You're absolutely right! I'm unsure yet whether we should change the documentation or the function's behaviour, but something should be fixed for sure. Thanks for the report! |
Hi all, I just noticed this exact problem (came here to report it too). @jni I would say that this is a bug, and so should be fixed:
It looks like the somewhat easy work-around right now is to convert the output to int arrays (which will do an int floor, which will give you a 1 pixel error half the time, or do a rounding to nearest int conversion |
@richard-moss thank you for your input! It's extremely valuable to hear the perspective of our users. Would you be comfortable submitting a fix in a pull request? I think using |
@jni I'll try to get to it the next few days. That approach does work fine (I'm using it in my code as the workaround), but I'll also check how polygon() etc are doing it right now (that do return int's when passed floats) to make sure it's in line with their implementation. |
Hey @richard-moss @jni ! Happy to see this issue, as I stumbled on the same problem. Any news about the fix? I would be happy to help, if needed :) |
skimage.draw.rectangle(start,end) with float input produces float output that cannot be used to index which is unexpected behavior compared to the other skimage.draw.* functions. See discussion at issue scikit-image#4283 scikit-image#4283 This patch implements np.round(...).astype(int) as suggested by @jni. Users who desire different behavior for float input can explicitly convert start, end to int as they desire before calling skimage.draw.rectangle(). np.round(...).astype(int) seems a reasonable default that behaves similarly to the other draw functions.
I also just ran into this and didn't expect to not be able to index with the output. From what I can tell polygon() also applies When I started working on the patch I began to question whether the desired behavior should be to produce a rectangle fully contained in the requested rectangle. Or a rectangle that fully contains the requested rectangle, etc. But I think that in the end for rectangle() it is easy for a user to do something different and send their own ints when needed rather than floats if desired. The np.round() approach at least guarantees that something reasonable happens by default rather than producing results that can't be used to index. |
* Support float input to skimage.draw.rectangle() [#4283] skimage.draw.rectangle(start,end) with float input produces float output that cannot be used to index which is unexpected behavior compared to the other skimage.draw.* functions. See discussion at issue #4283 #4283 This patch implements np.round(...).astype(int) as suggested by @jni. Users who desire different behavior for float input can explicitly convert start, end to int as they desire before calling skimage.draw.rectangle(). np.round(...).astype(int) seems a reasonable default that behaves similarly to the other draw functions. * Add test_rectangle_float_input
Description
When
skimage.draw.rectangle
gets float inputs forstart
andend
, the output is also float, which is unexpected as the docs say that the outputs should be array of ints. Documentation needs clarity as to whether float inputs are allowed and if so, what the expected behavior is.skimage.draw.polygon
returns array of ints whenr
orc
inputs are floats. However the behavior is not clear from the docs.Way to reproduce
Output:
Version information
The text was updated successfully, but these errors were encountered: