Algorithm for manual white balance(kelvin) and tint correction

2014-02-24
2014-03-07
  • pranjal rajput

    pranjal rajput - 2014-02-24

    Hello,
    I am developing a webgl shader to enable white-balance correction and tint correction of web-gl canvas images.
    Specifically, i wish to replicate the temperature slider on white-balance tab of UFRAW (but for jpeg images.)
    Please suggest the correct approach to do this. Any link or extract from relevant part in UFRAW source-code would be of great help to me.

    So far I have been able to:
    1) convert from rgb to xyz
    2) found the rgb values for given kelvin temperature based on this (http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/)

    Some precise notes on the exact transformations to be applied would be very helpful.
    PS: i dont want it to be scientifically accurate. as long as it mimics ufraw or adobe camera raw upto a decent level, it will do for me.

    Thanks a lot,

     
  • pranjal rajput

    pranjal rajput - 2014-02-28

    I have been able to adapt function Temperature_to_RGB from ufraw_routines.c to get the rgb values for given kelvin temperature.
    I am stuck at third but last line.

    The source code:

    uniform sampler2D texture;
    uniform float temperature;
    float RGB[3];
    float XYZ_to_RGB[9];
    float xD, yD, X, Y, Z, max;
    float T;
    varying vec2 texCoord;
    void main() {
    vec4 color = texture2D(texture, texCoord);
    T = temperature;
    XYZ_to_RGB[0] =3.24071;XYZ_to_RGB[1] =-0.969258;XYZ_to_RGB[2] =0.0556352;
    XYZ_to_RGB[3] =-1.53726;XYZ_to_RGB[4] =1.87599;XYZ_to_RGB[5] =-0.203996;
    XYZ_to_RGB[6] =-0.498571;XYZ_to_RGB[7] =0.0415557;XYZ_to_RGB[8] =1.05707;
    RGB[0] = color.r;RGB[1]=color.g; RGB[2]=color.b;
    if (T <= 4000.00) {
    xD = 274750000.00 / (T * T * T) - 985980.00 / (T * T) + 1174.44 / T + 0.145986;
    } else if (T <= 7000.00) {
    xD = -4607000000.00 / (T * T * T) + 2967800.00 / (T * T) + 99.11 / T + 0.244063;
    } else {
    xD = -2006400000.00 / (T * T * T) + 1901800.00 / (T * T) + 247.48 / T + 0.237040;
    }
    yD = -3.00 * xD * xD + 2.87 * xD - 0.275;
    X = xD / yD;
    Y = 1.00;
    Z = (1.00 - xD - yD) / yD;
    max = 0.00;
    for(int c = 0; c < 3; c++) {
    RGB[c] = X * XYZ_to_RGB[c] + Y * XYZ_to_RGB[3+c] + Z * XYZ_to_RGB[6+c];
    if (RGB[c] > max) max = RGB[c];
    }
    for(int c = 0; c < 3; c++) {
    RGB[c] = RGB[c] / max;
    }
    /stuck here. how to replace the old values with new values? /
    color.rgb = vec3((RGB[0]+color.r)/2.00,(RGB[1]+color.g)/2.00,(RGB[2]+color.b)/2.00);
    gl_FragColor = color;
    }

     
  • pranjal rajput

    pranjal rajput - 2014-03-07

    looks like no-one cares. !!!!

    thanks for the 50+ views anyway.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks