Skip to content

[ENH]: rgb_to_hsv/hsv_to_rgb could check that the inputs are of floating point dtype #22651

@anntzer

Description

@anntzer

Problem

If one passes 8-bit RGB values to rgb_to_hsv, the results are nonsensical. rgb_to_hsv indeed explicitly states that inputs should be 0-1 floats, but it is not too difficult to accidentally pass 8-bit values instead (e.g., plt.imread() is inconsistent as to whether it returns one or the other).

Proposed solution

rgb_to_hsv could include some check for that.

  • Checking that all values are exactly in [0, 1] may not actually be a good idea, as you could sometimes have values just a slop below 0 or above 1 due to earlier FP errors.
  • I would instead suggest checking that the input is of floating point dtype; technically one could be passing a 0-1 image with integer dtype (where all the values are 0 or 1) but this seems rare and confusion-prone anyways.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions