Skip to content

HSI->RGB conversion may return a value out of [0,1] #378

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

Closed
kimikage opened this issue Dec 15, 2019 · 2 comments · Fixed by #407
Closed

HSI->RGB conversion may return a value out of [0,1] #378

kimikage opened this issue Dec 15, 2019 · 2 comments · Fixed by #407

Comments

@kimikage
Copy link
Collaborator

FWIW, HSI->RGB conversion may return a value out of [0,1].

julia> convert(RGB, HSV(90,1,1))
RGB{Float32}(0.5f0,1.0f0,0.0f0)

julia> convert(RGB, HSL(90,1,1))
RGB{Float32}(1.0f0,1.0f0,1.0f0)

julia> convert(RGB, HSI(90,1,1))
RGB{Float32}(1.0f0,2.0f0,0.0f0)

This is not consistent with other conversions to RGB. However, the conversions from HSV and HSL also do not check the input range.

julia> convert(RGB, HSV(400,2,2))
RGB{Float32}(2.0f0,0.66666603f0,-2.0f0)

julia> convert(RGB, HSL(400,2,2))
RGB{Float32}(0.0f0,1.3333333f0,4.0f0)

julia> convert(RGB, HSI(400,2,2))
RGB{Float32}(5.26083f0,2.73917f0,-2.0f0)

IMO, it makes sense to clamp the values which are not numerically meaningful or the values ​​which exceed typemin/typemax, but otherwise it is unnecessary.
If we consider color gamuts other than sRGB, we will need to reconsider the clipping.

@kimikage
Copy link
Collaborator Author

One use case where this problem become tangible is calling hex.

julia> hex(HSI(90,1,1))
ERROR: ArgumentError: element type FixedPointNumbers.Normed{UInt8,8} is an 8-bit type representing 256 values from 0.0 to 1.0,
  but the values (1.0f0, 2.0f0, 0.0f0) do not lie within this range.
  See the READMEs for FixedPointNumbers and ColorTypes for more information.

I removed the clamping, i.e. stopped using lerp, in PR #387, because:

  • the clamping is done in XYZ/YIQ/YCbCr --> RGB conversion, i.e. Lab, Luv and so on also do not require the extra clamping
  • the normal HSV and HSL space do not exceed the normal RGB space
  • RGB colors should be used in [0,1], so, the clamping is the responsibility of the user

@kimikage
Copy link
Collaborator Author

I'm going to add the clamping in the HSI-->RGB conversion. (cf. #407)

kimikage added a commit that referenced this issue Mar 4, 2020
This adds the clamping and hue normalization for sources to HSx-->RGB conversions.
This also adds the clamping for destinations to HSI-->RGB conversion.
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 a pull request may close this issue.

1 participant