I do not think that using an np.arange(n) is a reasonable/common to do by the way. What is the expected behavior?
I've seen it used for demo/testing for quickly creating an array with a range of values (it is being used in a unit test). In the context of this discussion, it is just an example of a way a user may end up with an array of int32s without really thinking about it, thereby getting themselves into trouble.
Maybe we can check whether the upper bound is satisfied. That probably wouldn't hurt much if we convert any way.
I think that might be the best way.
Also, we should stress in the (at the moment not really existing) user guide, that users should NEVER EVER use "astype" on an image, since that violates all our assumptions.
I completely agree. However, the explicit use of "astype" is just one of many ways to find yourself in this situation. e.g.:
x = np.arange(9).reshape((3, 3)) + 1. y = skimage.img_as_ubyte(x) y array([[255, 254, 253], [252, 251, 250], [249, 248, 247]], dtype=uint8)
The core issue is to make sure that users know the assumed range for floats. Neil