You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarification regarding object returned by imread #333
All docs say that imageio.imread return a numpy array.
A few tests show that it's not exactly the case, it's returning an imageio.core.util.Image instance.
So I'm guessing this Image instance is (partially?) duck-typing a numpy array.
How can I get a native numpy array from this object ?
Should this be clarified in README, docs ?
Reacted by Clint Rhea, LucaMarconato and Ioannis Valasakis
The image data produced by imageio is a numpy array. It is a subclass, so that meta data can be attached, but other than that it is a normal array. You can turn it into a regular array using e.g. np.asarray(im).
That said, I understand the confusion, and you're not the first to mention this. This topic is mentioned here in the docs, but maybe we should mention it in more places.
I've also considered making the result look more like a numpy array. E.g. by overloading __repr__, but that may be fragile, and maybe it's also wrong, because that would mean we're hiding the fact that it is a subclass...
@almarklein Thanks for the reply. IMO it should be mentioned in this doc that the object is a numpy-like object, that can be converted to a pure numpy array using np.asarray. Should be more than enough. What do you think ?
I agree. I will make a small section somewhere in the docs to explain this, and change the docstrings in imread and friends to be more precise about what is returned, and link to the aforementioned section.
For the record though: it is a true numpy array, isinstance(im, np.ndarray) == True, and it behaves as any array. The only difference is that it has a meta dict attached, and it has a different name in the repr.
Activity
almarklein commentedon Apr 10, 2018
The image data produced by imageio is a numpy array. It is a subclass, so that meta data can be attached, but other than that it is a normal array. You can turn it into a regular array using e.g.
np.asarray(im).That said, I understand the confusion, and you're not the first to mention this. This topic is mentioned here in the docs, but maybe we should mention it in more places.
I've also considered making the result look more like a numpy array. E.g. by overloading
__repr__, but that may be fragile, and maybe it's also wrong, because that would mean we're hiding the fact that it is a subclass...almarklein commentedon Apr 10, 2018
I'm welcoming to suggestions :)
Overdrivr commentedon Apr 12, 2018
@almarklein Thanks for the reply. IMO it should be mentioned in this doc that the object is a numpy-like object, that can be converted to a pure numpy array using
np.asarray. Should be more than enough. What do you think ?almarklein commentedon Apr 12, 2018
I agree. I will make a small section somewhere in the docs to explain this, and change the docstrings in imread and friends to be more precise about what is returned, and link to the aforementioned section.
For the record though: it is a true numpy array,
isinstance(im, np.ndarray) == True, and it behaves as any array. The only difference is that it has ametadict attached, and it has a different name in the repr.