Repository navigation
Decorators for helping with the multichannel->channel_axis transition - #5228
Conversation
|
Hello @grlee77! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-03-05 13:21:09 UTC |
…tion deprecate_multichannel_kwarg handles deprecation of the multichannel argument and conversion to the new channel_axis form channel_as_last_axis helps automatically move channels to the end for compatibility with existing code channels in the output will be restored back to their original position Apply the channel_axis change to montage and test with different channel axes
2c9babb to
14ace98
Compare
|
|
||
|
|
||
| def test_montage_simple_rgb(): | ||
| def test_montage_simple_rgb(channel_pos=-1): |
There was a problem hiding this comment.
not sure what channel_pos is used for here
There was a problem hiding this comment.
It should not be there. I originally started modifying this test class, but later decided to leave this one using multichannel and add a new test_montage_simple_rgb_channel_axes test case instead to test the channel_axis argument.
|
Thanks @grlee77 the approach looks sound to me. So ? |
silence whitespace errors E201, E202, E203 in test_*.py and colorconv.py where small arrays are defined using spacing favorable for reading by humans
Yes, this way we don't have to make solutions for every functions individually to support alternative channel positions. If there are cases where it makes sense to handle the channels in a different manner, then those functions can implement that internally and stop using the
Yes, If the input array is C-contiguous with channels as the first axis then after import numpy as np
a = np.ones((3, 256, 256))
a_reordered = np.moveaxis(a, 0, -1)
# overall array is now no longer C-contiguous
print(a_reordered.flags)
# but invidual channels are C-contiguous
print(a_reordered[..., 0].flags)Also |
emmanuelle
left a comment
There was a problem hiding this comment.
Thanks @grlee77 the PR is ready as far as I'm concerned. @scikit-image/core we need another review please :-)
|
Looks good to me; I guess we'll know more once we start using this in practice. |
DOC: add channel_axis description to docstrings
|
I added a couple of additional functions to illustrate additional arguments for the
This PR now covers all |
|
Thanks @jni, I made the requested modifications. |
|
Thank you @grlee77! The failed checks appeared to be due to a stalled VM. |
This PR is related to #4294. It introduces two new decorators to help with the proposed transition from
multichanneltochannel_axis:1.)
deprecate_multichannel_kwargis a decorated based ondeprecate_kwarg, but additionally takes care of converting values from:multichannel=False -> channel_axis=None
multichannel=True -> channel_axis=(-1,)
2.)
channel_as_last_axiscan be used to help automate shuffling of axes to/from the last position. This will not be needed for functdions capable of handling arbitrary channel positions, but is a quick way to adapt many existing functions that all assume channels correspond to the last axis.For now I just applied these to the existing
montagefunction as a concrete example. I want to get initial feedback before extending the approach further. Right now only a single channel axis is supported, but thechannel_as_last_axisdecorator could also be adapted to handle more general cases.