I have a digital camera that takes photos 24x7 and it often depending on the weather returns images with a nasty color cast. Generally blue.
I have been trying to find some source code or library that I can call from c# to reduce the color cast of the images.
Photoshop has a feature that works quite well on the images I tested which is:
This works well, but I do not know what it is doing.
I am not good at the maths so was looking for ideas on existing code or libraries that I could just use.
I have been searching the web but not found anything useful - would love some help.
Tuning White Balance automatically cannot always work nice, because your algorithm will have less information as input data (no real light metering, only pixel values recorded by matrix, some of which may be clipped). So this can help when camera's setting is ridiculously wrong (like on your picture), but it cannot make WB right. You'd better buy a decent camera (there are even cheap ones that still can do good pictures)
BTW, if you want to invent a wheel, the idea is to scale color channels to make their average level equal. You can try different definitions of "average" here, and you can also try to exclude pixels with clipped values from measurement. But there is no fun in doing it again, as there are good ways to do this mentioned in @mickro's answer.
This looks like the White Balance is set for indoors (expecting reddish light) but getting daylight (blue). GIMP has a color temperature slider that will change the cast of the pictures. Are you talking about preventing this in the future, or batch processing a bunch of existing images. Even simple cameras (but maybe not mobile phones) have controls on white balance, for future shots.
This looks like a web cam plugged into your computer? So it is probably a moving target, meaning that the WB is being re-evaluated each time it takes a pic, and you may not be able to apply the same correction to each image.
Here is an imagemagick script which can batch process color temperature on a bunch of images. I think an approach which uses the temperature would be better than one that is just normalizing levels, because what if you are shooting the sky or ocean, and it should be blue? You just want to make sure it is the right blue.
Edit: For specific C# code, you might check here. The lower-left example in the first set of color balanced images look very much like your source image. There is also white balance function in the source code of paint.net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With