-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Restandardize handling of Multi-Image files #2815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The tests are legitimately failing on Travis-CI for this PR. |
5899e76
to
b072f05
Compare
I think I resolved the test failures by explicitly passing load_func=None in MultiImage to trigger the old behaviour. I could not find a reason for the special imread definition there, and removing it doesn't seem to affect tests. This feels slightly odd and also makes MultiImage quite redundant (all it does is set the _filename attribute). The whole thing feel slightly fragile, since even specifying just load_func=imread automatically removes the flattening of multi-frame files. It seems no tests catch this with imread_collection, which does exactly that. I don't what the better way would be. Should there perhaps be an explicit parameter for enabling the flattening behaviour? |
My intuition is that we should never flatten. Each file should map to one image (array). We can build a special interface to load multi-images and unpack them, but as you suggest, that should be explicit. |
I separated all the multi-image functionality from ImageCollection to a inherited class FrameCollection and implemented MultiImage on top of that. Now ImageCollection is completely frame-agnostic, and just sees each frame as its own image, with _files corresponding to the _frame_index. MultiImage is now just a simple passthrough to Framecollection, and I think it could probably be deprecated as it adds no real functionality (as was apparently discussed before: #1200). Any comments on the class organization? There's still some niggles to fix before it's ready for merging:
|
I added the Existing functionality should now work as it was, just with FrameCollection instead of ImageCollection. |
Doesn't FrameCollection and MultiImage now do the same when called on a multi-frame image? |
@stefanv Yes, FrameCollection is just the existing MultiImage, that now also handles multiple images. MultiImage probably should be deprecated in favor of FrameCollection, with warnings before removing it completely? |
Why not just replace MultiImage with the FrameCollection implementation? Do they have differing APIs? |
The API is different in that FrameCollection handles multiple multi-images. I'm not sure what you mean by replacing, do you want to keep the MultiImage class name (even though it now handles multiple files as well)? |
I think, since we only added functionality, and since the old calls will still work, we can probably keep the MultiImage name, yes. |
I figured it would be more clear to make a new class that explicitly handles any sets of frames, but I guess keeping MultiImage as the name is not too confusing. |
Another option is to add an |
Adding the parameter would make for a lot of branching in ImageCollection. Having the FrameCollection/MultiImage just inherit ImageCollection makes the latter much cleaner. |
There is the small API change of MultiImage having the |
OK, then let's keep MultiImage, and just set the filename parameter to the file pattern, for backward compatibility. We can make it a property, and warn that that property is being deprecated. |
Or, just keep it, and have it contain the file pattern :) Since this is new functionality, no-one should notice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks!
I left some minor nitpicks, but overall good to go.
Is your name in the CONTRIBUTORS file, by the way? Please add it.
skimage/io/collection.py
Outdated
load_pattern : str or list | ||
Pattern glob or filenames to load. The path can be absolute or | ||
relative. Multiple patterns should be separated by os.pathsep, | ||
e.g. '/tmp/work/*.png:/tmp/other/*.jpg'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backticks for code, ``/tmp/work/*.png:/tmp/other/*.jpg``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for ``os.pathsep``
above
skimage/io/collection.py
Outdated
The current implementation makes use of ``tifffile`` for Tiff files and | ||
PIL otherwise. | ||
By default, MultiImage builds a list of frames in each image | ||
and calls ``imread(filename, img_num=n)`` to read the n:th frame in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some indication that it is being called for each n
Done. To summarize the current version as compared to master:
|
This looks great; thanks @maaleske! |
@scikit-image/core This PR went through review and has been approved; if another person could take a look, rebase and merge, please. |
I have deleted my comment starting with "Sorry for the gross series of 'Remove extra lines' commits..." -- I thought I wouldn't be able to push from my local branch and, hence, had to work with the online editor (because I couldn't when I wasn't core, but anyway). |
I have tried updating this PR in line with #3928 but I'm afraid I have lost the original spirit of this contribution along the way... 😞 There are now 3 failing tests in
Note that function @jni could you please have a look? Thanks 😬 |
Forgot to loop in @alexdesiqueira, especially when referring to #3928 🙏 |
I realize this PR is three years old, so it might be unrealistic to include it at this point... I thought I would give it a try, since it was tagged with
Removed in fad090c.
Removed in 335be36. |
Since the pattern parameter was changed, the tests I added are probably outdated since they were meant to check for differences w.r.t. the original behaviour. It's probably best to disregard them and just make sure that you test whatever is needed to check for the issues in #5069 and #2811 (if that one still happens). |
@maaleske great to read you!! Sure. Specifically, we want |
Oh, I wasn't aware of #4859... 🤦♀️ It's okay: I've spent enough time in this code by now that I would be fast at reworking either PR. Which one of the two PRs do we want to close, @jni? @alexdesiqueira I don't think we want to keep both in parallel, indeed. My general comment remains the same: My understanding is that we want to remain in the spirit of #3928 and build from there. Notably, we want to accept loading patterns which are either strings or lists of strings (not lists of anything as in the original contribution). Besides, if we keep (as I suggest we do) the handling of multi-pattern brought by #3928, the detection of frames as implemented in the original contribution fails at splitting frames within a given (multi-image) file. Therefore, we can only keep a marginal part of this contribution on the functionality side. But we should keep most tests brought by this contribution (yay!) even if some need adapting. |
@mkcor @alexdesiqueira I gotta say I don't understand this stuff anymore! 😅 To me it seems that either PR can go forward, #4859 was a simple rebase. Since @mkcor you have made some nice updates here, I think we can just close #4859 and keep going here! |
@jni I don't know if we can squeeze this fix into @cosinus11 eeffe8a fixes #5069. In the end, I respected the original vision outlined by @maaleske and @stefanv:
Namely, an image collection of (multiple) multi-frame file(s) has a tree structure when specifying a loading function ( The changes brought by this PR don't overwrite those brought by #3928 -- still, it would be great if you could review, @alexdesiqueira! 😄 |
Additional notes:
|
Thank you very much for your attention and your reactivity, amazing! |
Thank you all for your feedback and work put into this PR; given that this has been reviewed by more eyes than most other PRs, I am putting it in. Thanks @maaleske ! |
@meeseeksdev backport to v0.18.x |
Wow, thank you so much @maaleske for the original work, and @alexdesiqueira @mkcor for the resurrection, and @stefanv for the merge! Amazing to not have this looming over my head anymore! 😂 |
Co-authored-by: Matti Eskelinen <matti.a.eskelinen@gmail.com>
Thank you very much everyone! Sorry for not reviewing again* @mkcor, thank you for your work! |
Description
Checklist
[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]
./doc/examples
(new features only)References
Closes #2811
For reviewers
(Don't remove the checklist below.)
later.
__init__.py
.doc/release/release_dev.rst
.