Skip to content

Deprecate gray scale image support for rgb2gray - #4438

Merged
emmanuelle merged 4 commits into
scikit-image:masterfrom
rfezzani:Deprecate_gray_scale_image_support_in_rgb2gray
Apr 9, 2020
Merged

emmanuelle merged 4 commits into
scikit-image:masterfrom
rfezzani:Deprecate_gray_scale_image_support_in_rgb2gray

Conversation

@rfezzani

@rfezzani rfezzani commented Feb 9, 2020 •

Copy link
Copy Markdown
Member

Description

Fixes #3200

Following @hmaarrfk comment, this PR is a prerequisite to #4418.

Checklist

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@rfezzani rfezzani mentioned this pull request Feb 9, 2020
2 of 11 tasks
Comment thread skimage/color/colorconv.py Outdated
"""

if rgb.ndim == 2:
warn('Gray scale image conversion is now deprecated.',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supposed that the new behavior would be described when implemented, in #4418 :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that an error should be raised if the last dimension is not 3, what ever is the number of dimensions

@rfezzani rfezzani added the 🔽 Deprecation Involves deprecation label Feb 10, 2020

@hmaarrfk hmaarrfk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. '

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a multichannel argument to allow the user to use the new behavior today

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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). 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, ...]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again confused 😄! rgb2gray(rgb[np.newaxis, ...])[0, ...] is valid in this PR, and gray2rgb(image[np.newaxis, ...])[0, ...] also if we remove this line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding these advises when the 3D support is effectively allowed (in #4418)? 😉

Comment thread skimage/color/colorconv.py Resolved
@rfezzani

Copy link
Copy Markdown
Member Author

Any other required change @hmaarrfk ?

@hmaarrfk hmaarrfk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rfezzani

Copy link
Copy Markdown
Member Author

Thank you @hmaarrfk ;-)

@hmaarrfk

Copy link
Copy Markdown
Member

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.

@rfezzani

Copy link
Copy Markdown
Member Author

I personally believe that the old behavior was confusing: how rgb2gray can accept grayscale as input 😄

@rfezzani

Copy link
Copy Markdown
Member Author

Anyone can review this PR? It is prerequisite for #4418... Thx

@rfezzani

rfezzani commented Apr 8, 2020

Copy link
Copy Markdown
Member Author

This PR is the only remaining prerequisite for #4418, a second review please ;-)

@emmanuelle

Copy link
Copy Markdown
Member

ok, let's merge this one. The ensure gray or ensure rgb was nice indeed but it just adds a test on the number of dimensions (we should assume that users know the geometry of their data, or they can always test the value of the last dimension).

@emmanuelle
emmanuelle merged commit 47f8e67 into scikit-image:master Apr 9, 2020
@rfezzani

rfezzani commented Apr 9, 2020

Copy link
Copy Markdown
Member Author

Thank you @emmanuelle 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔽 Deprecation Involves deprecation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should rgb2gray accept gray images?

5 participants