65 self, old_lum: FloatImagePlane, new_lum: FloatImagePlane, a: FloatImagePlane, b: FloatImagePlane
66 ) -> tuple[FloatImagePlane, FloatImagePlane]:
68 Adjusts the color saturation while keeping the hue constant.
70 This function adjusts the chromaticity (a, b) of colors to maintain a
71 consistent saturation level, based on their original luminance. It uses
72 the CIELAB color space representation and the `luminance` is the new target
73 luminance for all colors.
77 old_lum : `FloatImagePlane`
78 Luminance values of the original colors.
79 new_lum : `FloatImagePlane`
80 Target luminance values for the transformed colors.
82 Chromaticity parameter 'a' corresponding to green-red axis in CIELAB.
84 Chromaticity parameter 'b' corresponding to blue-yellow axis in CIELAB.
88 new_a : `FloatImagePlane`
89 New a values representing the adjusted chromaticity.
90 new_b : `FloatImagePlane`
91 New b values representing the adjusted chromaticity.
95 chroma1_2 = a**2 + b**2
96 chroma1 = np.sqrt(chroma1_2)
100 chromaMask = chroma1 == 0
101 chroma1[chromaMask] = 1
107 sinHue[chromaMask] = 0
108 cosHue[chromaMask] = 0
112 div = chroma1_2 + old_lum**2
116 sat_original_2 = chroma1_2 / div
121 * correction_factor**2
124 / (1 - sat_original_2 * correction_factor**2)
129 chroma2 = np.sqrt(chroma2_2)
135 new_a = chroma2 * cosHue
139 new_b = chroma2 * sinHue