-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add a channel_axis argument to functions in the skimage.color module #5462
Conversation
TST: test rgb2hsv and hsv2rgb with variable channel_axis
add channel_axis to rgb2rgbcie, rgbcie2rgb add channel_axis to gray2rgb, gray2rgba, rgb2gray, rgba2gray
add channel_axis to rgb2lab, lab2rgb, xyz2lab, lab2xyz
support channel_axis for hsv_value and each_channel decorators
add channel_axis support to convert_colorspace
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-08-09 20:26:13 UTC |
I would be very tempted to drop
Exactly. It's not robust at all and it doesn't generalize to nD. I'm a little scared when I read: "A very simple check of the array shape is used for detecting RGB images, so
I searched all GitHub and found that this project by @lauraluebbert uses |
I decided to use |
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.
I'm only half-way through, but it's getting late; will finish during the week!
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.
I'm confused: I couldn't find channel_as_last_axis
defined in skimage/_shared/utils.py
--where is it?
channel_axis=channel_axis | ||
), | ||
img_rgb, | ||
) |
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.
Nice! 🙂
Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
False alarm, sorry, I don't know what happened to my sed/grep... 😕
line 220 of expected file in current |
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.
Thank you @grlee77, I left some suggestions, otherwise it LGTM 😉
alpha = np.full(arr.shape, alpha, dtype=arr.dtype) | ||
elif alpha.shape != arr.shape: | ||
raise ValueError("alpha.shape must match image.shape") | ||
rgba = np.stack((arr,) * 3 + (alpha,), axis=channel_axis) |
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.
❤️ Very elegant 😉
return rgba | ||
|
||
|
||
def gray2rgb(image, alpha=None): | ||
def gray2rgb(image, *, channel_axis=-1): |
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.
The alpha
argument may had be removed in a different PR, but it may be more complicated. Please remove the corresponding item in TODO.txt 😉
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.
Apparently I did already remove alpha
and the TODO item as part of #5463 so perhaps we should merge that first to make this cleaner.
Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
Thanks @rfezzani, I implemented the requested changes in the last few commits. |
@grlee77, we will be ready for merge after conflict resolution 😉 |
🎉 Thank you again @grlee77 |
Description
This PR adds a new
channel_axis
argument to color conversion functions as discussed a bit in #5439 and corresponding recent API-related meetings.For most functions this is pretty simple, often just requiring adding the
channel_axis
keyword and the pre-existingchannel_as_last_axis
decorator. Most of the work was in modifying the test cases to test each function with additional channel axis choices.One specific case that is a bit tricky is how to handle the
adapt_rgb
decorator so that it supports channels along any axis instead of always assuming the last axis. I implemented something for that in commit 8063049 that involves inspection of keyword arguments of the decorated function, but I think this is possibly too magical and is perhaps not worth it. It doesn't help thatadapt_rgb
is also one place where we apparently still try to guess if an image is RGB/RGBA based on its shape. The only function in the library that usesadapt_rgb
isskimage.exposure.equalize_adapthist
. If we don't want this change I can just revert that commit and/or leave it to a potential future follow-up PR.Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.