Skip to content

Finding color space information about image #2175

Closed

Description

@AbdealiLoKo

Description

I notice that currently after I read an image from skimage, there is no metadata that is further provided. For example, if I want to check if the image is greyscale or not, In Pillow I could do:

>>> im = Image.open('image.jpg')
>>> is_grey = lambda im: im.mode == 'L'

to make a function for checking if grey or not. In skimage, I'd have to do:

>>> im = skimage.io.imread('image.jpg')
>>> is_grey = lambda im: im.ndim == 2

But the ndim checkingmethods are not very nice because I may have a GIF file or TIFF file with multiple pages which is black and white - Making the ndim == 3.

Is there a better way to do this ? I found skimage does some similar dimension checking internally - https://github.com/scikit-image/scikit-image/blob/master/skimage/color/colorconv.py#L63

I was wondering whether it would be possible for skimage to expose helper functions to use Pillow's (or the plugin's) mode checking (Which uses header info and so on to detect the color space)

Activity

  1. soupault commented on Jun 30, 2016

    @soupault
    Member

    @AbdealiJK yes, that is a well known issue. See the following related pages: #1940, #1995.

    The discussion in #1995 is still open, feel free to contribute to it.

  2. added
    ⏩ type: Enhancement
    on Jun 30, 2016
  3. soupault commented on Jun 30, 2016

    @soupault
    Member

    Another story is how to improve type/ndim checking, which we have almost everythere. And that one could be addressed via some kind of fused types - #2126 (comment). I think we need to start a discussion some day on this as well. :)

  4. stefanv commented on Feb 15, 2017

    @stefanv
    Member

    scikit-image operates on numpy arrays exclusively, so we have no way of knowing (independently of the underlying plugin used) metadata about the image.

    I think we can extend all io plugins to have imread_metadata that returns both the image and any metadata available, in a dictionary with well specified keys, which should solve the problem.

    Any thoughts? /cc @jni

  5. soupault commented on Feb 15, 2017

    @soupault
    Member

    @stefanv yes, I think we've converged on this: #1995, #2240 (comment). I'll prepare SKIEP on this soon as the topic is being raised over and over again.

  6. jni commented on Feb 20, 2017

    @jni
    Member

    @stefanv I think the goal is to outsource IO to imageio sometime soon. At that point, we can just do

    def imread(x, **kwargs):
        return np.array(imageio.imread(x, **kwargs), copy=False)
    
    def imread_meta(x, **kwargs):
        im = imageio.imread(x, **kwargs)
        return np.array(im, copy=False), im.meta

    and forget about "plugins"...

  7. stefanv commented on Jul 15, 2017

    @stefanv
    Member

    See #2709

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions