From 17c99f6cc556f3a60edb9cb9e7bc5d659bb4f667 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sun, 25 May 2025 09:01:27 -0600 Subject: [PATCH 1/3] Modified `colorsynth.rgb()` to clip the upper bound using the tanh(x) function instead of a hard threshold. --- colorsynth/_colorsynth.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/colorsynth/_colorsynth.py b/colorsynth/_colorsynth.py index b6cc23e..31270d1 100644 --- a/colorsynth/_colorsynth.py +++ b/colorsynth/_colorsynth.py @@ -803,7 +803,10 @@ def rgb( ) RGB = RGB.to_value(u.dimensionless_unscaled) - RGB = np.clip(RGB, 0, 1) + + RGB = np.tanh(RGB) + + RGB = np.clip(RGB, 0, None) return RGB From f86a576fc077c045a176b2a08499070d19b7a588 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sun, 25 May 2025 20:20:17 -0600 Subject: [PATCH 2/3] different approach --- colorsynth/_colorsynth.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/colorsynth/_colorsynth.py b/colorsynth/_colorsynth.py index 31270d1..76fa101 100644 --- a/colorsynth/_colorsynth.py +++ b/colorsynth/_colorsynth.py @@ -804,7 +804,12 @@ def rgb( RGB = RGB.to_value(u.dimensionless_unscaled) - RGB = np.tanh(RGB) + max_rgb = RGB.max(axis, keepdims=True) + RGB = np.where( + max_rgb > 1, + RGB / max_rgb, + RGB, + ) RGB = np.clip(RGB, 0, None) From 0810697c5a42bf785ea1cf194f75bdaecd88f703 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Tue, 27 May 2025 16:31:53 -0600 Subject: [PATCH 3/3] clarifying --- colorsynth/_colorsynth.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/colorsynth/_colorsynth.py b/colorsynth/_colorsynth.py index 76fa101..fe44b48 100644 --- a/colorsynth/_colorsynth.py +++ b/colorsynth/_colorsynth.py @@ -805,11 +805,10 @@ def rgb( RGB = RGB.to_value(u.dimensionless_unscaled) max_rgb = RGB.max(axis, keepdims=True) - RGB = np.where( - max_rgb > 1, - RGB / max_rgb, - RGB, - ) + + max_rgb = np.maximum(max_rgb, 1) + + RGB = RGB / max_rgb RGB = np.clip(RGB, 0, None)