Repository navigation
Conversation
This is inspired by PIMS.
|
Well from #563 it is pretty obvious that I like the slicing idea. I would choose not to give Have you thought about with imageio.ImageSequence("some_file.tif") as seq:
# Fancy selection - proper cleanup even with exceptions/errors
img = seq.read()
# file has now been cleaned-up |
This is done throughout Python. When slicing a list (i.e.,
This is already implemented. However, |
True, and I agree with this rationale. I missed the functions when I first read the code; my bad.
You are absolutely right; I think I have misunderstood the intent of the interface; do you aim for it to be applicable to sequences of 2D images only, or were you thinking about sequences of nd-images? For sequences of 2D images, this convention is indeed clear and actually pretty smart. For nd-images, I wonder how the user would request the third image in the fourth stack in a sequence of volume images. In such a case, would you return volumes only? |
|
Thanks @lschr! It's really nice to see what this could look like. That said, in the end I think I prefer an API based on functions without mimicking an array. I mentioned a few arguments in #563. Another came to mind as I read through the example code here: I fear that an API like this can trick people into moving the Reading data and processing data are different stages, and having a different API is fine. I understand how this indexing API can provide sort of a lazy loading mechanism, which can be really nice in some cases, but in most cases it's better to load the data and close the file asap. Preferably under a (short) context manager. What this code here also shows, is that an index-based API can quite easily be built atop the existing imageio API, and surely this will hold for the new API as well :) |
|
@FirefoxMetzger This is just thin wrapper around |
|
@almarklein I didn't intend this as a replacement of the function-based API, but as an extension of the “advanced” I work in fluorescence mircoscopy, where it is common to record long sequences of images exciting alternatingly with different light sources. In this case being able to select the image type by slicing (e.g., with ImageSequence("some_file.tif") as ims:
mimwrite("every_other_frame.tif", ims[::2])As the sequences are often several GB in size, it is not possible to load everything into RAM and then do the slicing. I understand your concerns about misuse like not closing files, but these are already true when using Of course I could move this to a separate project (as you said, it is merely built on top of the existing API), but I do believe that it should be a part of imageio. |
2876712 to
b40d4c4
Compare
Clean up, add API documentation and tests.
b40d4c4 to
11c90cc
Compare
|
I finished the implementation, including docs and tests. The test fails for two reasons:
|
I disagree here. Yes, an advanced user knows what to do, but a novice will easily be confused. By looking at the code alone, it would be very easy to mistake the object for an array object.
Making this an alternative API based on the existing one can make sense, but I'm not sure whether it should be part of imageio. I'd prefer to keep imageio simple and provide just one API. If the use-cases for the proposed API are very common, than we could consider making it a utility of imageio, but I doubt that this is the case, to be honest. I know you put effort into this, and I can see how it really helps your use-case. My suggestion would be to create a new library. I would be ok with refering to it from the imageio docs. |
|
This will for now be part of my sdt-pyhon package. A link in the documentation would be nice so that people know that this exists. Should I make a pull request once a new version of sdt-python containing the |
|
Closing this one since it has been superseded by #574 that is now merged. I still like the idea of a sliceable interface to control which section of data will get loaded; however, knowing what I know now, I realize that this approach will be doomed as a general API for all plugins in ImageIO. For example, SPEv3 is a format that (from what I understand) stores sequences of ROIs which by default have unique shapes. Similarily, TIFF has a subIFD tag that allows creating a hierarchical layout inside a TIFF file. One of the use-cases for this is to attach thumbnails or downsampled versions of the image to the image itself. These, too, come in different shapes and a sliceable interface would be unintuitive. However, there are definitely good examples for when such a sliceable interface is useful, e.g., with large volumetric data that you don't wish to load into memory in one swoop. For these cases, a sliceable interface can (maybe should) be added to the respective plugins that can benefit from it. This interface would then be available for that specific plugin inside a with iio.imopen("...", plugin=...) as file:
# the resource was opened with a specific plugin for which
# a sliceable interface makes sense
# the common API still works
data = file.read(index=3)
# but a plugin-specific sliceable API is available, too
data = file[5:7, ...] |
Some examples:
Key points:
ImageSequenceobjectThis is work in progress. Documentation as well as tests are missing, but I would like some feedback before spending more time on it. Inspired by PIMS.