scikit-image / scikit-image

Image processing in Python
https://scikit-image.org
Other
6.04k stars 2.22k forks source link

rank filter maximum incorrect doc of output dtype #3577

Open vpoughon opened 5 years ago

vpoughon commented 5 years ago

Description

The documentation of skimage.filters.rank.maximum says that the returned array has the same dtype as the input:

Returns: | out : 2-D array (same dtype as input image)

However this is not the case for bool.

Way to reproduce

import numpy as np
from skimage.filters.rank import maximum

arr = np.random.randint(2, size=(10, 10)).astype(bool)
print(arr.dtype)
result = maximum((arr), selem=np.ones((3, 3)))
print(result.dtype)

Output:

bool uint8

Tested on skimage 0.14.1.

Related to #466, #1244, #1010

Henley13 commented 5 years ago

Do you want to update the documentation or make the function consistent (an input bool should return an output bool) ?

sciunto commented 5 years ago

As we discussed, I advised that in skimage, we try to keep the input and output dtypes identical.

stefanv commented 5 years ago

@sciunto Note that, currently, our explicitly stated policy is that we give no guarantees of output types. E.g., when doing interpolation, it would make no sense to stick to integers.

hmaarrfk commented 5 years ago

bools are strange datatypes. I would argue that you are likely not getting any benefit from using them as inputs on modern processors, and that this might constitute premature optimization. My opinion would be to simply use a uint8 with two possible values.

Cython doesn't seem to give a good way to handle boolean objects, possibily because there are no good instructions on modern processors that deal with the boolean datatype.

We explored how we might incorporate booleans into the workflow, but it doesn't seem like a good idea:

https://github.com/scikit-image/scikit-image/pull/3981#issuecomment-508952914

Honestly, I'm suggesting we bug out on boolean datatypes, but I understand that is a harsh reaction.

hmaarrfk commented 5 years ago

Nice, well relevant discussion seems to have happened https://github.com/numpy/numpy/issues/9251

But even with some patch from @soupault , I'm still getting



TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead
michalkrawczyk commented 3 years ago

Has anything changed with that issue? Cause when I was trying to reproduce - I got: ValueError: dtype cannot be bool.

Also: As I remember bool is actually uint8_t. In many applications have False if value is 0, if any other - True