Skip to content

Clarification regarding object returned by imread #333

Closed

Description

@Overdrivr

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 ?

Activity

  1. almarklein commented on Apr 10, 2018

    @almarklein
    Member

    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...

  2. almarklein commented on Apr 10, 2018

    @almarklein
    Member

    I'm welcoming to suggestions :)

  3. Overdrivr commented on Apr 12, 2018

    @Overdrivr
    Author

    @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 ?

  4. almarklein commented on Apr 12, 2018

    @almarklein
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions