Skip to content

Use-Case based lists of common formats/plugins #633

Closed

Description

@FirefoxMetzger

A while back @almarklein and I were discussing that we want to separate imageio and its backends (pillow, tifffile, ffmpeg, ...). To keep things convenient, we mused about creating a curated list of extra dependencies that would be used to install backends for a specific subject area. For example pip install imageio[microscopy] would install all backends related to microscopy.

To get this process rolling (and for us to get an overview of what plugin does what - and ultimately make the docs prettier) I created a spreadsheet listing all the extensions that imageio currently supports combined with the respective plugin for that extension. I've also added a suggestion for an initial set of install targets. Namely:

  • common: Add support for commonly used every-day formats (.png, .gif, .jpg, ...)
  • microscopy: Add support microscopy formats (.tiff, etc.)
  • video: Add support video formats (.avi, .mp4, etc.)
  • all: Install all backends

Here is a list to the spreadsheet: https://docs.google.com/spreadsheets/d/1na7fVHtdixXycRduPD0dGYdaLg6gEKR2dBW5LU9-FQk/edit?usp=sharing

Please let me know what you think. If I don't hear too large protests, I will go ahead and create a PR reflecting this suggestion.

Activity

  1. almarklein commented on May 17, 2021

    @almarklein
    Member

    I'm leaning towards making Pillow and tiffile standard dependencies, and making the freeimage plugin non-default. Otherwise this looks good to me. Nice work on the matrix spreadsheet :)

  2. FirefoxMetzger commented on May 17, 2021

    @FirefoxMetzger
    ContributorAuthor

    By standard dependencies you mean that they would be installed via pip install imageio[common]? I agree with pillow, since it is very popular and supports everyday formats. I'm not sure I understand tifffile; pillow already offers basic tif support which makes tifffile seem like a specialist backend.

    If you are thinking about core dependencies (pip install imageio), I would install neither pillow, nor tifffile. This would make us depend on numpy only, which should give a significant boost in flexibility.

  3. kmilos commented on May 18, 2021

    @kmilos
    Contributor

    I vote against narrow category naming like microscopy, higher bit depth and various compression TIFFs are used in many domains. Btw, tifffile will also happily read/interpret DNGs and some other TIFF-based photography raw files...

  4. FirefoxMetzger commented on May 18, 2021

    @FirefoxMetzger
    ContributorAuthor

    I vote against narrow category naming like microscopy,

    Sure, any alternative suggestions?

    You will always be able to get any backend combination you want via something line pip install imageio[freeimage, tifffile, spe], that is if your platform supports the respective backends. You can also add backends via good old pip install tifffile, etc.

    The added categories are pure QoL and I'm happy to update categories or category names. Microscopy would be meant for the Biomedical community, where we (somewhat) know the formats they typically use; maybe something like biomed would be a better name?

    Btw, tifffile will also happily read/interpret DNGs and some other TIFF-based photography raw files

    Cool! The spreadsheet I made is based on the current imageio docs. Our current implementation selects backends based on file extension first. There is a fallback mechanism if the file has no extension, but it sometimes fails to find the correct plugin to use, e.g. #604

    This is clearly not so optimal when backends update and add formats since we need to add that extension here, too. Our new plugin system should do a better job with this though since it passes the primary responsibility of knowing which formats a format can handle to the plugin. A good plugin will then use the backend's resolution method to check if the backend can handle the file, and that should update automatically as backends update. File extensions may of course still be used as a heuristic to speed up the search for a compatible backend ;)

  5. almarklein commented on May 19, 2021

    @almarklein
    Member

    I think I meant core then. If pip install imageio installs only numpy, it would be nice and lean, but I think users would expect to be able to read common image files without any special installation trickery. So I'd definitely argue to include Pillow by default. Tifffile is more specialized indeed, but because it's a small/light dependency with quite broad use, I think it makes sense to include it by default as well.

  6. FirefoxMetzger commented on May 19, 2021

    @FirefoxMetzger
    ContributorAuthor

    Hmm, maybe I am approaching this from a different (wrong?) angle. Here's my logic; please feel free to point out what I'm missing.

    There are multiple use-cases we are trying to serve. One comes from end-users who want to use imageIO directly in their script (or jupyter notebook or w/e). Another use-case comes from developers who want to use imageIO as a dependency for their library or executable, e.g. what scikit-image is doing. The former values a very easy installation process and lots of out-of-the-box features; the latter values minimal 3d party dependencies and wide platform support. I am trying to best serve both worlds.

    The option of having pip install imageio add pillow (and tifffile) would be very neat for the end-user use-case. It does however pose challenges for the developer use-case because pillow is a heavy, C-based dependency, which comes with the usual nightmare of managing cross-platform C libraries. If pillow is not supported on a platform imageIO (via pip install imageio) will not be supported neither. Of course, there is a workaround via pip install --no-deps imageio && pip install numpy, but I don't find this convincing. A developer affected by this will need to know (and track) imageIO's 3d party dependencies manually. Maintaining this also means making the downstream installation process more brittle. As a downstream dev, I would - personally - rather pass on imageIO than implement this workaround.

    Pillow not working on some platforms or having a new version that breaks stuff has been an issue for us in the past (thinking about some of the pypy issues we had). I also think this is one of the reasons why matplotlib ships its own .png reader and has pillow as an optional dependency only.

    The option of having pip install imageio install only bare-minimum dependencies would be neat for the developer use-case. It does however pose challenges for the end-user use-case, because pip install imageio won't do much out-of-the-box (unless backends were already present), which can be confusing. The workaround here would be to keep an extra requirement for the end-user use-case (e.g. common) that would install the backends via pip install imageio[common]. It is not so good, because the vast majority of packages install via pip install <libname>, so it can be unexpected and potentially confusing to new users. At the same time I think that, if the "Getting Started" section of the docs asks you to pip install imageio[common] most users will just copy/paste without a second thought.

    So to me it is a question of choosing between two workarounds: pip install imageio[common] for end-users vs pip install --no-deps imageio && pip install numpy [+ future imageio deps] for libraries. I think pip install imageio[common] is the lesser evil here.

    It also has the advantage of making base imageIO a library that you can easily "wedge" into almost any existing pipeline, giving you access to a lot of new formats for free. This might have positive implications for further uptake/growth of the library.

  7. almarklein commented on May 25, 2021

    @almarklein
    Member

    I see your point, and like your breakdown. However, I'm not convinced yet :)

    I think I consider Pillow to be more reliable than you do. It has been pretty consistent in delivering working versions for all platforms on pypi. What pypy issues are you referring to? I remember #598 but that has nothing to do with Pillow.

    Yes, we can document that ppl should use pip install imageio[common], but many users will also simply read to (or be told to) install imageio. And I think as an image io lib a minimal install should at the least be able to install png and jpg.

  8. FirefoxMetzger commented on May 25, 2021

    @FirefoxMetzger
    ContributorAuthor

    And I think as an image io lib a minimal install should at the least be able to install png and jpg.

    Fair point. How about we keep pillow for now with the plan to eventually make it optional and instead ship a dedicated reader for png (and jpg)? similar to what matplotlib is doing now.

    Also, what about other backends like tifffile? Should they also be installed by default, or become optional?

  9. almarklein commented on May 31, 2021

    @almarklein
    Member

    Fair point. How about we keep pillow for now with the plan to eventually make it optional and instead ship a dedicated reader for png (and jpg)? similar to what matplotlib is doing now.

    That sounds fair. Note: PNG is relatively easy (well defined format, and Python has zlib compression), but I'm not sure how we can support jpg without something binary to rely on.

    I think tifffile can be optional if that's what you prefer.

  10. clbarnes commented on Jun 3, 2021

    @clbarnes
    Contributor

    I am personally a big fan of imageio as a unified interface; as thin as possible a wrapper around whatever image-loading library would throw its hat into the ring. In that case, keeping it light and trivial to install would be a goal. That said, it's not worth removing the most common of use cases, in case there are users not familiar with extras who would skim over an image IO library which can't do any image IO by default.

    Another possible consideration would be making sure that imageio's interface could easily be used in other libraries - maybe experimental libraries for specific formats which aren't ready or valuable enough to add the API surface to imageio. It would be great for the image software ecosystem in general for such a user to be able to use imageio's base classes, utilities, and global format registry in their own library, so they can use the library's and their own interchangeably. In that case, we would want to keep imageio pretty thin by default.

    If the decision was made to really make imageio really really thin, one option would be to break out imageio.core into its own library. imageio would then import that, bundle a few different default backends, and provide extras for the rest. Image format tinkerers and applications which want to be generic over "things which imageio can read" would be able to just depend on imageio-core and immediately have their library compatible with the rest of the ecosystem without needing to contribute back to imageio. Meanwhile, we don't mess what people have (very gratefully) come to expect from imageio as it is today. We can even put together a "powered by imageio" badge for those using imageio as a compatibility bridge 😉

    Lastly, this would allow development work on the interface to progress independently from the library which people are using to read and write their images: you could tinker with and test the interface without feeling like you should be updating a dozen plugins too.

  11. FirefoxMetzger commented on Jun 3, 2021

    @FirefoxMetzger
    ContributorAuthor

    @clbarnes I linked this issue in your PR, because - from how I understand it - the "formats" option that you are contributing matches the "all" option that we have up for discussion here.

    I was wondering if you think adding options between everything and individual backends makes sense, and if so how they would look like.


    Some off topic replies:

    If the decision was made to really make imageio really really thin, one option would be to break out imageio.core

    I remember discussing this with @almarklein a while back. Alternatively, we considered outsourcing some of the plugins that are currently shipped together with imageio into their own repos (imageio-<plugin_name>).

    What we settled for is to keep the core and plugins in the same repo (easiest to maintain; if we want to make changes to the core, we can have a battery of unit tests that reduce the chances of us breaking a plugin), but to outsource backends as much as possible (also easiest to maintain, because not vendoring code means less code to maintain + automatic benefits for users if upstream fixes bugs). You can read more about this here #574 (comment) (only the section with a heading is relevant for this). There are some minor changes to what I wrote there back then and I will put all this info [in its final version] into the docs, once the dust has settled on the exact shape of the new API.

    tinkerers [...] would be able to just depend on imageio-core [...] without needing to contribute back to imageio.

    We decided against having a module that plugins depend on, and will instead have a (likely internal) minimal API to which plugins adhere to to communicate with the core.

    On a tangent, we would love for people to contribute their plugins back to us (the plugin, not the backend), because this way we have an easier time to ensure we aren't breaking compatibility as we go about improving imageio :) Ofc, if the backend already adheres to a similar API, then the plugin itself becomes a very lean wrapper that essentially just calls the corresponding function in the backend.

    you could tinker with and test the interface without feeling like you should be updating a dozen plugins too.

    Not sure I understand you correctly here. Assuming you are talking about the user-facing side of imageio, this is pretty much what we are going for in v3 #569 . The idea is to have an imopen factory that mimics builtin open and handles plugin selection and instantiation. Due to popular demand, we also ship a functional API (imread, imwrite, imiter), that wraps imopen under the hood. If a downstream application/library would like to consume imageio differently, they can do the same thing and wrap imopen similar to our functional API. For example, you could build a slicing interface on top - which was an alternative, semi-popular, suggestion for the v3 API design which didn't survive.

    Alternatively plugins can introduce plugin-specific methods that are exposed downstream. ImageIO guarantees read/write/iter/meta, but beyond that plugins can add whatever makes sense for the particular backend they are offering.

  12. FirefoxMetzger commented on Nov 25, 2021

    @FirefoxMetzger
    ContributorAuthor

    I am going to leave a link here for future reference:
    https://docs.openmicroscopy.org/bio-formats/6.7.0/supported-formats.html

    Bioformats is a Java-based library that - similar to ImageIO - provides read and write access to various images. It focuses on biomedical images and they have a list of supported formats. I was thinking this could be relevant here because we could compare that to our list and then add a pip install imageio[bioformats] target (or pip install imageio[microscopy]) that would install support for all of those formats (to the extent we support them).

  13. FirefoxMetzger commented on Apr 19, 2022

    @FirefoxMetzger
    ContributorAuthor

    I am closing this issue as the solution that established itself is to have each plugin/backend as its own optional dependency. However, this doesn't mean that we will never have plugin collections (use-case-based or otherwise). It simply means that we will keep this on hold until an explicit need for this arises.

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