You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: deprecate multichannel= in favour of channel_axis= #4294
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.
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.
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.
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
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.
@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.
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".
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 secondchannel axis.
@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.
@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.
@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.
Activity
grlee77 commentedon Nov 13, 2019
I also happened to use exactly this
channel_axisnaming 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 callswapaxeson 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.jni commentedon Nov 13, 2019
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_axisis 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.lagru commentedon Nov 13, 2019
Not sure about the feasibility of the optimizations but I really like API a
channel_axisargument would enable. It kinda reflects NumPy's well establishedaxisargument. +1hmaarrfk commentedon Nov 13, 2019
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.
emmanuelle commentedon Jan 29, 2020
Also +1 on this.
hmaarrfk commentedon Feb 8, 2020
What about cases where there are multiple channels??? Fluorescence and z for example?
jni commentedon Feb 8, 2020
z is not a channel, it’s a spatial axis.
soupault commentedon Feb 8, 2020
@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=andtime_axis=. That would make us closer to xarray, since the spacing for the special dimensions is often not constant and would need axis indices.hmaarrfk commentedon Feb 8, 2020
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
phaseare you speaking of? Isphasenot 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".
soupault commentedon Feb 11, 2020
Hmm... I typically associate
channelwithfrequencyorfrequency range. Although, I guess, you are right,phaseis a channel, but can be a secondchannelaxis.hmaarrfk commentedon Feb 11, 2020
So you would have amplitude and phase for each wavelength of light you are measuring?
jni commentedon Feb 12, 2020
@hmaarrfk @soupault I think you are applying a lot of scope creep to this issue. I propose the following, and only the following:
multichannel=Truebecomeschannel_axis=-1.multichannel=Falsebecomeschannel_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,TZCYXvolumes (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 thataxis=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_tuplefor those situations. To go back toTZCYX, you would pass inchannel_axis=(0, 2), e.g. if you wanted to apply a Gaussian filter over the space dimensions. (You could also dochannel_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.
soupault commentedon Feb 12, 2020
@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_axiswould also be great. And I did not mean to block the proposal in any way.21 remaining items
mkcor commentedon Jan 29, 2021
@grlee77 no objection, I'm +1 on @jni's suggestions!
stefanv commentedon Jan 29, 2021
@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.
jni commentedon Jan 30, 2021
@stefanv isn't this a matter of transposing the channel axis to the final axis?
grlee77 commentedon Feb 10, 2021
I think so. Please see #5228 which proposes a couple of decorators to help with this transition.
imagesc-bot commentedon Mar 2, 2021
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/acquire-order-of-dimensions-during-loading/49623/2
imagesc-bot commentedon Jun 15, 2021
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/display-multi-channel-images-with-scikit-image/51009/9
grlee77 commentedon Jun 21, 2021
Let me also make a small PR to update
release_dev.txtto describe this API change then I think we can close this one!grlee77 commentedon Jun 21, 2021
release notes added in #5438
stefanv commentedon Jun 21, 2021
Thanks, Greg!
Update scale.py