Repository navigation
Deprecate gray scale image support for rgb2gray - #4438
emmanuelle merged 4 commits into
Conversation
| """ | ||
|
|
||
| if rgb.ndim == 2: | ||
| warn('Gray scale image conversion is now deprecated.', |
There was a problem hiding this comment.
Honest question, do we want to raise an error in the future?
I guess for a line scanner a 1D image with RGB channels make sense.
Maybe we want to specify how we will be interpreting this in the future?
There was a problem hiding this comment.
I think this warning messages needs to be fleshed out more.
The behavior of rgb2gray will change in scikit-image 0.19. Currently, rgb2gray allows 2D grayscale image to be passed as inputs and leaves them unmodified as outputs. In version 0.19, this will no longer be these images will be treated as 1D images with 3 channels.
There was a problem hiding this comment.
I supposed that the new behavior would be described when implemented, in #4418 :-)
There was a problem hiding this comment.
I think that an error should be raised if the last dimension is not 3, what ever is the number of dimensions
hmaarrfk
left a comment
There was a problem hiding this comment.
Need to request changes in order to "revoke" my past approval.
| """ | ||
|
|
||
| if rgb.ndim == 2: | ||
| warn('The behavior of rgb2gray will change in scikit-image 0.19. ' |
There was a problem hiding this comment.
I think we need a multichannel argument to allow the user to use the new behavior today
There was a problem hiding this comment.
@hmaarrfk I thought about that, but then that suggests either that we will remove the multichannel argument in the future (another breaking change 🤦♂️) or that it will do nothing in the future (not great either), or that we will continue to support multichannel forever (which as far as I know is false at this point). 🤔
There was a problem hiding this comment.
This was always the blocker for this deprecation.
I don't think this new behavior is too critical, so we can avoid the introduction of the new parameter.
There was a problem hiding this comment.
Yes, the warning message is explicit enough to not make the user confused: old users are not disturbed since the old behavior is kept, and users needing the new behavior need to wait version 0.19.
To avoid this warning, they only have to check to not provide 2D arrays as input...
Same argument is valid for #4440
There was a problem hiding this comment.
@rfezzani I got confused between the two PRs. In this one, it's fine, as the 2D use case isn't that compelling. In the other one, people who want to convert 3D images to RGB where the last dimension has shape 3 have no way to use the library in a future-proof way.
There was a problem hiding this comment.
In the other one, people who want to convert 3D images to RGB where the last dimension has shape 3 have no way to use the library in a future-proof way.
We may advise to add a dummy dimension and to remove it after conversion
rgb2gray(rgb[np.newaxis, ...])[0, ...]
There was a problem hiding this comment.
Again confused 😄! rgb2gray(rgb[np.newaxis, ...])[0, ...] is valid in this PR, and gray2rgb(image[np.newaxis, ...])[0, ...] also if we remove this line.
There was a problem hiding this comment.
Ah! Advising reshapes before and after is a great idea! 🎉 Could you add the correct one in each case? =)
gray2rgb(image.ravel()).reshape(image.shape + (3,)) will work for nD gray2rgb.
There was a problem hiding this comment.
What about adding these advises when the 3D support is effectively allowed (in #4418)? 😉
Co-Authored-By: Egor Panfilov <[email protected]>
…into Deprecate_gray_scale_image_support_in_rgb2gray
|
Any other required change @hmaarrfk ? |
hmaarrfk
left a comment
There was a problem hiding this comment.
Im fine with this PR as is.
These kinds of conversions are trivial and users that need the special cases we don't support yet can do the reshaping tricks.
These edge cases seem small enough that today, I anticipate that they affect a very small number of users.
|
Thank you @hmaarrfk ;-) |
|
Yeah. I have a PR open for this nD conversion as well, but didn't have a partner that was as motivated as me at the time. Hopefully somebody else can put the nail on this one. What scares me is that by providing conveniences for advances users, we are forgetting conveniences for novice users. This "ensure grayscale" or "ensure RGB" was quite convenient. |
|
I personally believe that the old behavior was confusing: how rgb2gray can accept grayscale as input 😄 |
|
Anyone can review this PR? It is prerequisite for #4418... Thx |
|
This PR is the only remaining prerequisite for #4418, a second review please ;-) |
|
ok, let's merge this one. The |
|
Thank you @emmanuelle 🎉 |
Description
Fixes #3200
Following @hmaarrfk comment, this PR is a prerequisite to #4418.
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.@meeseeksdev backport to v0.14.x