Spadge
asked on
Colour lightening algorithm
I'm looking for an algorithm to take an RGB colour value and lighten it by a percentage, basically to simulate what happens when you set the opacity of a photoshop layer to e.g. 20% in front of a white background.
Any ideas?
Any ideas?
ASKER
So far I have tried converting to HSB then increasing brightness and reducing saturation, e.g. where P = percent by which to lighten, using the ranges H=[1-360], S=[0-1], B=[0-255]:
B = B + ((255 - B) * (100 / P))
S = S * (100 / (100 - P))
The trouble with this is that it causes quite an exponential rate - changes of 10% and 20% are barely different, while a change of 99% is noticably brighter than one of 98%.
I am working in VB, but I just need an algorithm - the language of the solution is not especially important.
Thanks.
B = B + ((255 - B) * (100 / P))
S = S * (100 / (100 - P))
The trouble with this is that it causes quite an exponential rate - changes of 10% and 20% are barely different, while a change of 99% is noticably brighter than one of 98%.
I am working in VB, but I just need an algorithm - the language of the solution is not especially important.
Thanks.
ASKER
Sorry - too early in the morning here! I meant:
B = B + ((255 - B) * (P / 100))
S = S * ((100 - P) / 100)
B = B + ((255 - B) * (P / 100))
S = S * ((100 - P) / 100)
Perhaps this might help more ..
https://www.experts-exchange.com/questions/20154464/Image-intensity-transformations.html
Cheers,
T.
https://www.experts-exchange.com/questions/20154464/Image-intensity-transformations.html
Cheers,
T.
ASKER
Not really :-(
His algorithm for lightening makes the following change:
L = HSL.Lum + (HSL.Lum * Percent)
Where L is the same as my B value. Whereas the algorithm I already have increases L/B by a percentage of the difference between itself and the maximum, his increases it by a percentage of itself.
The reason mine is different is because I want to consistently raise the brightness of different colours. With his, if I have two colours X and Y, X has a brightness/luminance of 5% and Y of 70% and I brighten both by 50%, X will end up with a brightness/luminance of 7.5%, while Y will end up with 105% rounded down to 100% - a much greater jump and not consistent.
Additionally, I am changing the saturation value too - without this the colour gets richer so not strictly just brighter.
I think my problem is in the way I am changing saturation.
His algorithm for lightening makes the following change:
L = HSL.Lum + (HSL.Lum * Percent)
Where L is the same as my B value. Whereas the algorithm I already have increases L/B by a percentage of the difference between itself and the maximum, his increases it by a percentage of itself.
The reason mine is different is because I want to consistently raise the brightness of different colours. With his, if I have two colours X and Y, X has a brightness/luminance of 5% and Y of 70% and I brighten both by 50%, X will end up with a brightness/luminance of 7.5%, while Y will end up with 105% rounded down to 100% - a much greater jump and not consistent.
Additionally, I am changing the saturation value too - without this the colour gets richer so not strictly just brighter.
I think my problem is in the way I am changing saturation.
Hi,
I don't know anything about the programming, but quite sure that you're tryin' to adjust the Level of the image. In photoshop, select (on the menu bar) Image>Adjustment>Levels...
I don't know how Level command works in terms of algorithm, but you might find your answer there.
I don't know anything about the programming, but quite sure that you're tryin' to adjust the Level of the image. In photoshop, select (on the menu bar) Image>Adjustment>Levels...
I don't know how Level command works in terms of algorithm, but you might find your answer there.
ASKER
If anyone is interested in the solution, in the end the best approach turned out to be to 'mix' the colour with white, so for example to brighten a colour by 80% take 20% of the R, G and B values of the colour and add them to 80% of the R, G and B values of white. This simulates Photoshop's opacity changes *perfectly* (the resultant colours match those produced by Photoshop exactly), and you can simulate opacity over any colour - not just white.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cheers,
T.