Skip to content

Proposal: deprecate multichannel= in favour of channel_axis= #4294

Closed

Description

@jni

This might need a SKIP. =P But won't if we get unanimous agreement!

The name multichannel is a bit clunky. Worse than that, it does not quite provide sufficient information: we hardcode the channel axis as -1, which might actually be incorrect. Allowing for arbitrary channel axes allows (1) giving the data in acquisition axis order, which often does not have the channels as the last axis, and (2) allowing channels to be the leading axis, which in many cases is more efficient, as the processing happens independently on each channel (e.g. gaussian filtering), and this is more cache friendly if each channel is contiguous.

Over at napari, we've settled on channel_axis=None being equivalent to multichannel=False, and channel_axis=<int> to point to an axis to interpret as channel rather than spatial data. I quite like it, and seeing an issue like #4293, where we might want to either specify no channels or a different channel axis makes me think that we can refine scikit-image to use this also.

Looking forward to hearing your thoughts!

Activity

  1. grlee77 commented on Nov 13, 2019

    @grlee77
    Contributor

    I also happened to use exactly this channel_axis naming in some local code dealing with multichannel MRI data, as some software assumed channels last while others assume channels are first.

    I am +1 on moving toward using channel_axis, but how do you anticipate handling existing code that assumes channels are the last dimension? The simplest solution is probably to manually call swapaxes on function input and then undo the swap on output, but that comes with some performance penalty for cases where the channel axis is not already last.

  2. jni commented on Nov 13, 2019

    @jni
    MemberAuthor

    how do you anticipate handling existing code that assumes channels are the last dimension? The simplest solution is probably to manually call swapaxes on function input and then undo the swap on output

    Yes, that would be my proposal. The API matters much, much more than performance. We can deal with performance later, when it becomes a measured problem. This would not be a performance regression for any existing code. We can do plenty of approximate tweaks, like, if channel_axis is 0, and the image size is greater than 4MB (or your L1 cache, or whatever), then do a copy of the axis swapped-data before processing. But we should not clutter the code with these until someone complains.

  3. added this to the 1.0 milestone on Nov 13, 2019
  4. lagru commented on Nov 13, 2019

    @lagru
    Member

    Not sure about the feasibility of the optimizations but I really like API a channel_axis argument would enable. It kinda reflects NumPy's well established axis argument. +1

  5. hmaarrfk commented on Nov 13, 2019

    @hmaarrfk
    Member

    My biggest fear is that the release cycle is too slow to make all this maintenance work worthwhile.

    It seemed that the biggest fear from our last conversation was that the deprecation cycle would be thrown off if we were to move to more frequent releases. That said, slow releases mean that we don't get feedback about new features for a long time.

    These big swooping changes require lots of input from core devs, which meqn that we often don't have time to evaluate other PRs that work on content and new analysis techniques.

    TLDR, I am +1, but would be +2 if combined with a more frequent release plan.

  6. emmanuelle commented on Jan 29, 2020

    @emmanuelle
    Member

    Also +1 on this.

  7. hmaarrfk commented on Feb 8, 2020

    @hmaarrfk
    Member

    What about cases where there are multiple channels??? Fluorescence and z for example?

  8. jni commented on Feb 8, 2020

    @jni
    MemberAuthor

    z is not a channel, it’s a spatial axis.

  9. soupault commented on Feb 8, 2020

    @soupault
    Member

    @hmaarrfk I was thinking the same. :) We should probably better define what image is and the extents of our scope in relation to such definition. For example, do we consider 2D Fourier transform (two frequency axes) to be a valid image for the library (i.e. support it as a valid input for most of the functions)? What about the data array where we have two dims of spatial data, third axis is frequency, fourth is phase, fifth is time? Should we support such data, in general? If so, we may want to consider adding phase_axis= and time_axis=. That would make us closer to xarray, since the spacing for the special dimensions is often not constant and would need axis indices.

  10. hmaarrfk commented on Feb 8, 2020

    @hmaarrfk
    Member

    Fourier transforms: Are complex, much of the C code doesn't work with complex numbers, and cython doesn't support them well, at least the last time I tried it didn't.

    What kind of phase are you speaking of? Is phase not a channel?

    I wouldn't worry too much about what the channels represent, more that there are "dimensions we want to operate on, and dimensions we want the operation to be repeated over".

  11. soupault commented on Feb 11, 2020

    @soupault
    Member

    What kind of phase are you speaking of? Is phase not a channel?

    Hmm... I typically associate channel with frequency or frequency range. Although, I guess, you are right, phase is a channel, but can be a second channel axis.

  12. hmaarrfk commented on Feb 11, 2020

    @hmaarrfk
    Member

    So you would have amplitude and phase for each wavelength of light you are measuring?

  13. jni commented on Feb 12, 2020

    @jni
    MemberAuthor

    @hmaarrfk @soupault I think you are applying a lot of scope creep to this issue. I propose the following, and only the following:


    • multichannel=True becomes channel_axis=-1.
    • multichannel=False becomes channel_axis=None.

    The proposal allows us to maintain backwards compatibility with all our current features and express one new thing, which is the case where the channels are arranged along a different axis, say, the leading axis, with:

    • channel_axis=0,
    • or, for say TZCYX volumes (common in microscopy), channel_axis=2.

    This is straightforward to implement (just needs a NumPy transpose before and after existing code), and is strictly more expressive than what we have now, and imho results in a more readable API.


    Metaphysical discussions about what constitutes a channel are interesting but imho only very mildly affect the discussion. I just met someone (@ericpre) who had, at every pixel of the image (spatial location in a sample), a full X-ray diffraction pattern (ie another 2D image). In this case, you could either ravel the pattern, or you could have a tuple input to channel_axis=, but that can come later, the same way that axis= gained the ability to receive tuples in NumPy ufuncs.

    Typically, pixels have spatiotemporal extent, while channels are measurements at the same location. When displaying images, channels are usually overlaid on top of each other. Other axes, like time, z, etc are sliced. Sure, there are contexts when you might want to treat time as a channel, but they are in the minority, and again, you can use channel_axis=a_tuple for those situations. To go back to TZCYX, you would pass in channel_axis=(0, 2), e.g. if you wanted to apply a Gaussian filter over the space dimensions. (You could also do channel_axis=2, sigma=(0, 3, 5, 5) to prevent smoothing over the time axis.)

    And I'm not sure why complex dtype images would affect the discussion at all. It's an orthogonal issue.

  14. soupault commented on Feb 12, 2020

    @soupault
    Member

    @jni My point above is rather an attempt to understand whether we should use this opportunity and make things a bit differently / more flexible. I generally agree with your definition of channels. However, I believe there are cases with multiple channels where one does not want to consider them similarly during the processing (e.g. filtering, inpainting). One of the examples could be a dual-energy X-ray captured in the form of both the absorption and the phase contrast images. On the other hand, such cases with multiple channels are probably pretty rare and are easily solvable by just iterating over the proper axis. To assist this, we should probably document how the channels are handled in each of the functions with multichannel support.

    Sorry, I did not make that clear that I support your original proposal. I think having a tuple as a valid parameter value in channel_axis would also be great. And I did not mean to block the proposal in any way.

  15. 21 remaining items

  16. mkcor commented on Jan 29, 2021

    @mkcor
    Member

    @grlee77 no objection, I'm +1 on @jni's suggestions!

  17. stefanv commented on Jan 29, 2021

    @stefanv
    Member

    @jni How does this complicate the implementation aspect? All algorithms now need to handle arbitrary channel positions, so will we write utilities to facilitate?

    In terms of the API, it encodes everything the old one did and more, so I am +1 overall.

  18. jni commented on Jan 30, 2021

    @jni
    MemberAuthor

    @stefanv isn't this a matter of transposing the channel axis to the final axis?

  19. grlee77 commented on Feb 10, 2021

    @grlee77
    Contributor

    @stefanv isn't this a matter of transposing the channel axis to the final axis?

    I think so. Please see #5228 which proposes a couple of decorators to help with this transition.

  20. imagesc-bot commented on Mar 2, 2021

    @imagesc-bot
  21. imagesc-bot commented on Jun 15, 2021

    @imagesc-bot
  22. grlee77 commented on Jun 21, 2021

    @grlee77
    Contributor

    Let me also make a small PR to update release_dev.txt to describe this API change then I think we can close this one!

  23. grlee77 commented on Jun 21, 2021

    @grlee77
    Contributor

    release notes added in #5438

  24. stefanv commented on Jun 21, 2021

    @stefanv
    Member

    Thanks, Greg!

  25. modified the milestones: 0.21, 0.20 on Jan 19, 2023
  26. added a commit that references this issue on Jul 3, 2023
  27. moved this to Done in skimage2on Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🔽 Deprecation📜 type: API💬 Discussion

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions