JuliaGraphics / Colors.jl

Color manipulation utilities for Julia
Other
200 stars 44 forks source link

Fixed tritanopia simulation #525

Closed williamjsdavis closed 1 year ago

williamjsdavis commented 1 year ago

Summary: Fixed a typo causing incorrect simulation of tritanopic color vision deficiencies. Also added tests for this corrected behavior.

This is my first pull request, I apologize if I have done anything incorrectly. I have been working with simulating various color vision deficiencies, and I noticed that the simulation for tritanopia was not producing results that I expected. Looking into the code in the function tritanopic had a typo:

https://github.com/JuliaGraphics/Colors.jl/blob/b550b7bc2f6f27fdf61c30b3215b28df826ceebf/src/algorithms.jl#L138

It should be:

(one(p) - p) * q.s + p * (-(a*q.l + b*q.m)/c))

This error can be easily observed when inspecting the behavior of the function at p=0 (no photopigment loss):

Screen Shot 2022-09-30 at 13 20 03

This can also be seen in the RGB values:

rgb = RGB(0.44, 0.26, 0.8)
rgb |> dump
tritanopic(rgb, 0) |> dump
RGB{Float64}
  r: Float64 0.44
  g: Float64 0.26
  b: Float64 0.8
RGB{Float64}
  r: Float64 0.4547022003851215
  g: Float64 0.2596348656158941
  b: Float64 0.33903165107645483

As a counterexample, the function protanopic is working correctly:

Screen Shot 2022-09-30 at 13 20 51
rgb = RGB(0.44, 0.26, 0.8)
rgb |> dump
protanopic(rgb, 0) |> dump
RGB{Float64}
  r: Float64 0.44
  g: Float64 0.26
  b: Float64 0.8
RGB{Float64}
  r: Float64 0.4400000030003578
  g: Float64 0.26000003129854465
  b: Float64 0.8000000074911268

This pull request fixes this typo, and adds three tests to validate this correct behavior. Please let me know if there are any questions.

codecov[bot] commented 1 year ago

Codecov Report

Base: 94.33% // Head: 95.51% // Increases project coverage by +1.18% :tada:

Coverage data is based on head (d117720) compared to base (b550b7b). Patch has no changes to coverable lines.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #525 +/- ## ========================================== + Coverage 94.33% 95.51% +1.18% ========================================== Files 9 9 Lines 1270 1270 ========================================== + Hits 1198 1213 +15 + Misses 72 57 -15 ``` | [Impacted Files](https://codecov.io/gh/JuliaGraphics/Colors.jl/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics) | Coverage Δ | | |---|---|---| | [src/algorithms.jl](https://codecov.io/gh/JuliaGraphics/Colors.jl/pull/525/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics#diff-c3JjL2FsZ29yaXRobXMuamw=) | `91.96% <ø> (+16.07%)` | :arrow_up: | | [src/utilities.jl](https://codecov.io/gh/JuliaGraphics/Colors.jl/pull/525/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics#diff-c3JjL3V0aWxpdGllcy5qbA==) | `95.60% <0.00%> (-0.74%)` | :arrow_down: | | [src/conversions.jl](https://codecov.io/gh/JuliaGraphics/Colors.jl/pull/525/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics#diff-c3JjL2NvbnZlcnNpb25zLmps) | `99.13% <0.00%> (-0.29%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaGraphics)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.