Regarding grayscale/desaturation

simonsanchezart
Posts:2
Joined:Mon Jul 15, 2019 2:34 am
Regarding grayscale/desaturation

Post by simonsanchezart » Tue Jan 19, 2021 12:03 am

Hello! I've got a bunch of feature requests regarding desaturation.

On the Smart Color Correction feature, the Output Saturation seems to be using Rec. 601:
(0.30 * r) + (0.59 * g) + (0.11 * b)

Based on that same formula, I think the next features would be useful:

- A toggle to quickly visualize the painting desaturated, this can be useful to check values.
- Hue Jitter in the brushes should use the formula above to choose it's colors, so the values are consistent.

The last option can be really useful to make paintings with a more impressionist style, as you make sure the hues will respect the value of the selected color.

I've tried to create a python app to get a color with the same value as the input color, it's brute-forcing it with recursion:

Code: Select all

import random

def GetGrayscale(r, g, b):
    value = (0.30 * r) + (0.59 * g) + (0.11 * b)
    return value

treshold = 0.0008
userR = float(input("r: "))
userG = float(input("g: "))
userB = float(input("b: "))
targetValue = round(GetGrayscale(userR, userG, userB), 3)

print(f"Target: {targetValue}")

attempts = 0
def GetB():
    global attempts
    attempts+=1

    r = random.random()
    g = random.random()
    b = (targetValue - ((0.30 * userR) + (0.59 * userG))) / 0.11
    
    finalValue = round(GetGrayscale(r, g, b), 3)

    if(finalValue >= targetValue - treshold and finalValue <= targetValue + treshold):
        print(f"r: {round(r, 2)}")
        print(f"g: {round(g, 2)}")
        print(f"b: {round(b, 2)}")
        print(f"Final Value: {round(finalValue, 3)} in {attempts} attempts")
    else:
        GetB()

GetB()
This is ugly but it works. The desaturation formula is a plane, if you randomly select a r and g value between 0-1, you can then solve the formula, finding b so the formula is equal to the value of the current selected color. I don't know math (couldn't limit b to 0-1) so I had to brute-force it.

I think these features could be great to make color paintings easier :)
Thanks!
Post Reply