Sign in to follow this  
JasonHise

Color Interpolation

Recommended Posts

For interpolation of colors, I had an idea to linearly interpolate the luminosity (vector distance from black) along with each color component, and then normalize each interpolated color based on that distance. The image on the left is linearly interpolated, and the one on the right is normalized based on luminosity. To me, normalizing based on luminosity seems to make a major improvement, removing the large dark area in the middle of the interpolated region. Is there a reason that this method of interpolation is not used more in practice? -Jason Edit: Here is some code for the interpolation methods I used. Linear:
color step ( color start, color end, float percent )
{
    color result;
    result.r = start.r * ( 1.0f - percent ) + end.r * percent;
    result.g = start.g * ( 1.0f - percent ) + end.g * percent;
    result.b = start.b * ( 1.0f - percent ) + end.b * percent;
    return result;
}


Normalized:
color step ( color start, color end, float percent )
{
    color result;
    float start_length = sqrt ( start.r * start.r +
                                start.g * start.g +
                                start.b * start.b );

    float end_length = sqrt ( start.r * start.r +
                              start.g * start.g +
                              start.b * start.b );

    float length = start_length * ( 1.0f - percent ) + end_length * percent;

    result.r = start.r * ( 1.0f - percent ) + end.r * percent;
    result.g = start.g * ( 1.0f - percent ) + end.g * percent;
    result.b = start.b * ( 1.0f - percent ) + end.b * percent;

    float cur_length = sqrt ( result.r * result.r +
                              result.g * result.g +
                              result.b * result.b );

    float ratio = length / cur_length;

    result.r *= ratio;
    result.g *= ratio;
    result.b *= ratio;

    return result;
}


[Edited by - 0xCHAOS on June 5, 2005 2:00:42 PM]

Share this post


Link to post
Share on other sites
The kind of interpolation you are describing is roughtly equivalent (in time) to interpolate the normal and not the color, and by interpolating the normal (so by doing phong shading), you'll get better lighting than with your mehtod. I think that's why this method of interpolation is not used more in practice. But it remains interesting to have mentioned it. You could also try to interpolate in HLS space, it could also result in better shading, and it would be more or less equivalent to what you are doing.

Share this post


Link to post
Share on other sites
Quote:
Original post by ptl
The kind of interpolation you are describing is roughtly equivalent (in time) to interpolate the normal and not the color, and by interpolating the normal (so by doing phong shading), you'll get better lighting than with your mehtod. I think that's why this method of interpolation is not used more in practice.


That makes sense.

Quote:
But it remains interesting to have mentioned it. You could also try to interpolate in HLS space, it could also result in better shading, and it would be more or less equivalent to what you are doing.


I would be interested to try that. I'll have to see if I can find or derive some RGB <-> HLS conversion formulas.

Share this post


Link to post
Share on other sites
Hi 0xCHAOS,

Your results look very interesting, and I was very curious to know whether this is a real improvement, so I asked on a forum full of specialists: Beyond3D.

It turns out that your method is a hack. But this is also good news, since your normalization process is very expensive (processing wise) compared to simple additions. The problem is that, while linear interpolation is physically correct, our monitors can't display it like that. Most monitors have a gamma of around 2.2, which means that grey values (128, 128, 128) will actually look darker than 'medium grey'. So while the color you use in the corner look bright, in the middle it becomes grey and the monitor doesn't properly display it without correction.

So the correction should happen -after- the image has been rendered totally, not during interpolation. Many applications already do this.

Share this post


Link to post
Share on other sites
Thanks for all the information! One thing is bothering me about the gamma corrected images however... it seems that it results in a loss of color information. The more you correct, the larger the grayish region in the center becomes, most noticably blotting out a lot of the blue area. Mathematically, how is gamma correction applied? How much gamma correction is generally used in modern applications/games?

Share this post


Link to post
Share on other sites
Yes, the gamma corrected images look a little pale. Your approach keeps the colors very vibrant, saturated. But really the only correct approach is the one with gamma correction.

Now, it's very possible that your monitor has a gamma lower than 2.2. On my laptop's LCD, a gamma of about 1.6 looks best. So it depends a lot on the actual monitor. If the blue gets 'pushed away' on yours, this probably means your monitor is badly calibrated. The links below (from the Beyond3D thread) can help with that:

http://www.aim-dtp.net/aim/calibration/index.htm
http://www.aim-dtp.net/aim/evaluation/gamma_space/index.htm

It also explains the formulas used for gamma correction, which is just an exponential function.

Most applications apply gamma correction via the graphics card's gamma ramp. The Direct3D SetGammaRamp function allows to change it directly. The gamma ramp is actually a translation table so you can do every kind of correction (e.g. contrast enhancement is an S-curve). Almost every game has a menu where you can adjust gamma.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this