# Script: Change color Saturation while maintaining L in LAB model

For example, I have a red color `#633b3d` (Saturation: `40`, L: `30`) and I want to transform Saturation to `80` while maintaining L (resulting color should be `#83211b`). If I simply change `foregroundColor.hsb.saturation` to `80`, lightness will change to `21`. If I restore L to the original color L, saturation will change to `66`... How can I change Saturation to a specific value while maintaining the L? I wrote `Lightness` in the image below, but I guess `Luma` is a more correct term.

I want to do this with a script so I can use JS libraries. Current code is simple Photoshop DOM:

``````var curColor = foregroundColor;

foregroundColor.hsb.saturation = 80;
foregroundColor.lab.l = curColor.lab.l;
``````
• did you succeed to find relativity between hsl or lab? i tried to figure it out but i'm failing. i googled it and found one site to convert it but again it's source code is missing from github colormine.org/convert/lab-to-hsl so by testing i felt like l and s constant seems like looking at left and right same time; anyway there might be way of that type of conversion but that's far i could go; hope it helps or anyway wanna know answer too so upvoted! May 24 '19 at 10:25
• anyway found the forumla of hsb to rgb but hsb to lab seems missing anyway hope this may help :) devx.com/tips/Tip/41581 May 24 '19 at 10:27
• I have formulas for converting between hsb and lab (easyrgb.com/en/math.php) my problem is to keep values from two different models. May 24 '19 at 10:34
• You should prbably use HCL insetad of HSB (that by the way does not really make sense) May 24 '19 at 15:32

In Lab color system your "Original" and "Target" colors have the same L, but in HSB their brightnesses are different. That's because Lab system is developed to present seen colors and HSB presents voltages in a color production machine (=RGB screen) Of course in HSB there's some attempt to take into the account eye's different sensitivity in different colors, but that's very coarse. It can be enough to make color televisions which at least seem to work, but still separates very poorly seen color and seen brightness when compared to Lab system.

You can set Photoshop's color picker to keep Hue and Brightness constant and give a slider to change the saturation. Slide it and see radical changes in Lab system's L.

As well, if you slide Lab's L, all numbers in HSB vary.

The most non-perceptual thing in HSB is the saturation. It presents how far away from each other are R, G and B in percents of the maximum possible in that brightness. Thus nearly pure white and nearly black can well be 100% saturated. Saturation isn't at all the same as colorfulness, it's in percents "how much there is colorfulness of the maximum possible in RGB at that brightness level"

In Lab system we have no single number for colorfulness. Numbers a and b hold as well hue and colorfulness (=chroma). If you want to keep hue unchanged, but increase chroma, you must multiply a and b with the same number. If you want to change only hue, keep sqrt(a^2+b^2) (that's chroma) same, change the ratio of a and b. You get easily out of RGB gamut colors, those which would need RGB values beyond the range 0...255. Photoshop clips the RGB numbers to 0...255. Fortunately Gamut Warning is possible to switch ON.

Your problem: If you must keep Lab's L, then change only Lab's a and b. Use adjustment mechanism which allows it, do not use a mechanism which works via HSB numbers. If you for some for me unknown reason must do the adjustment by changing HSB numbers, then you must adjust all of them to keep L.

• Thank you for your answer. I'm making a Hue-Saturation-Luma color sliders where H and S are locked on Luma: the idea is to be able to change H/S without visible perceived brightness change, so I can make a color, for example, more/less saturated but it won't look darker/brighter. Here's a quick demo: dropbox.com/s/bfqo2j1b8ttmwdw/luma-lock.gif?dl=0 When I change H and S, visible luma almost doesn't change, if I'd use a simple HSB sliders my values would be all over the place. At the moment I do that in an ineffective way so I was wondering if there's a straightforward conversion. May 24 '19 at 15:26
• @SergeyKritskiy CIELCH is a variation of Photohop's Lab color system. In CIELCH (aka HCL and LCH) number L is the same as Lab's L, but a and b are presented in polar form as H=hue and C=chroma. GIMP knows it. See the theory: en.wikipedia.org/wiki/CIELAB_color_space. Someone has also provided ready to use converter: colormine.org/convert/lab-to-lch As said before, it's not at all difficult to make a color which is undisplayable in RGB. May 24 '19 at 16:54