The trick is to know what the black value is for your sensor. This is the nominal value that the sensor records when there is no light.
You may be able to get the value in any case since there is part of the sensor that is not exposed. Possibly the average value of the first row.
Some publication also indicated that you can avoid the color shift and desaturation by using the following formula:
R = (Y'/Y*(R+Y) + R - Y)/2
G = (Y'/Y*(G+Y) + G - Y)/2
B = (Y'/Y*(B+Y) + B - Y)/2
Where Y is the luminance value before the change and Y' is the luminance value after the change.
It kind of partially works but cause some loss of contrast. Color correction seems a little bit more controllable.
I attached the code if you want to have some fun with it.
Note:
- I stored directly in the curvex[] table the (Y'/Y)*1024 value to avoid division which is not in ARM native instruction.
- I also cheated:
Y = (R+G)/2 for the red line
Y = (B+G)/2 for the blue line
Outdated attachment removed...