image processing: tint algorithm

Started by
3 comments, last by Josh Yelon 18 years, 11 months ago
Whats the correct way to tint an image a specific colour? I've tried an algorithm which adds the specified R,G,B components to the current pixel value ... but the result is not what quite what I'm looking for ( ok that bit is subjective ). Do I need to be messing around with colour histograms and such to do this properly. Mark
Advertisement
You could search the internet for information on different types of blend modes. This page seems to have a simple description of the common blend modes. Try looking at either Multiply or Screen, probably.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
What do you want to do exactly ? Adding a color tint to an image is usually done using a linear interpolation:


pixel.rgba = originalpixel.rgba * t + tintcolor.rgba * (1 - t)



Do you want omething more precise ?

HTH,
One way to do this is by transforming to the HSV colorspace, modifying the H (Hue) then transforming back. This has the effect of preserving the luminosity and saturation while changing the "color". You can find some good conversion routines here.

Example code:
const float tint_hue = 180.0f; // cyanfloat h, s, v;float fr, fg, fb;RGBtoHSV(r/255.0f, g/255.0f, b/255.0f, &h, &s, &v);HSVtoRGB(&fr, &fg, &fb, tint_hue, s, v);r = fr * 255.0f;g = fg * 255.0f;b = fb * 255.0f;

Since the calculated H value is unused, you can optimize RGBtoHSV a lot by removing the part that calculates H.

HTH.
-Melekor
If what you're trying to do is tint to create a "time-of-day" effect, I've found that it often looks good to convert to black-and-white first. Converting to black-and-white simulates the fact that at night, our eyes switch over from cones to rods.

if (time-of-day == NIGHT) then  tint = (0.8,0.8,1.0) // slightly blue  saturation = 0.4 // fairly desaturatedif (time-of-day == SUNSET) then  tint = (1.0,0.8,0.6) // reddish tint  saturation = 0.7 // not that desaturatedmono = original DOT (0.333,0.333,0.333)tinted = mono * tintfinal = saturation * original + (1-saturation) * tinted


- Josh Yelon
-- Distribution Maintainer, Panda3D
- Josh Yelon-- Distribution Maintainer, Panda3D Engine

This topic is closed to new replies.

Advertisement