Skip to content

Fix rgb2gray docstring to show that 2-D arrays are allowed as inputs - #4417

Closed
parekhnish wants to merge 2 commits into
scikit-image:masterfrom
parekhnish:rgb2gray-docstring-correction
Closed

parekhnish wants to merge 2 commits into
scikit-image:masterfrom
parekhnish:rgb2gray-docstring-correction

Conversation

@parekhnish

Copy link
Copy Markdown

Description

This is a docstring fix, refers to discussion in #3200, specifically this reply.

rgb2gray() allows 2-D arrays as inputs, but the docstring stated it would raise a ValueError. This PR does the following:

  • Changes the docstring to show that 2-D inputs are allowed.
  • Explains what happens to 2-D inputs (essentially, nothing changes except converting it to row-major order, if needed).

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

@parekhnish
parekhnish requested a review from jni January 28, 2020 06:23

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

Thank you @parekhnish for this contribution! You can see in my #3200 (comment) that the problem is heavier then expected.
I think that as long as we don't find an acceptable solution to the discussion #3200, we have to add mention in the Notes that channels with indices greater then 3 are ignored

The image in RGB format, in a 3-D or 4-D array of shape
``(.., ..,[ ..,] 3)``, or in RGBA format with shape
``(.., ..,[ ..,] 4)``.
``(.., ..,[ ..,] 4)``

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.

We have to remove the mention to arrays of shape (.., ..,[ ..,] 4) since _prepare_colorarray doesn't accept RGBA images.

ValueError
If `rgb2gray` is not a 3-D or 4-D arrays of shape
If `rgb` is a 1-D array, or not a 3-D or 4-D array of shape
``(.., ..,[ ..,] 3)`` or ``(.., ..,[ ..,] 4)``.

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.

Same as above, RGBA images are not supported...

``(.., ..,[ ..,] 3)``, or in RGBA format with shape
``(.., ..,[ ..,] 4)``.
``(.., ..,[ ..,] 4)``
or

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 can simply be added in the Notes section, what do you think?

@rfezzani rfezzani mentioned this pull request Jan 28, 2020
2 of 11 tasks

If there is an alpha channel present, it is ignored.

If the input array is 2-D, it is converted to a row-major (i.e. C-style)

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 would be fine adding al lthe comments in the Notes section stating that calling this function with 2D images, while supported for now, is heavily discouraged.

@soupault

Copy link
Copy Markdown
Member

@parekhnish thanks for your effort! The solution has been discussed in #3200 and implemented in #4438.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants