miniPaint icon indicating copy to clipboard operation
miniPaint copied to clipboard

White balance

Open anonimo82 opened this issue 3 years ago • 2 comments

Please, add some way to balance the white in a pic (in example, by specifying what should be considered white, then act accordingly)

Thanks for any help

anonimo82 avatar Jun 18 '22 13:06 anonimo82

I was looking into this, and it doesn't seem to be this simple. For camera users, what you generally need is a way to adjust the color temperature.

For example, I took a photo where the camera treats 3500k as the white point, so it should be adjusted to something like 6500k.

Color temperature adjustment algorithms aren't that simple, but there is an example here. https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html

The "pick a color" white point algorithm I see everywhere online is generally making the assumption that the picked color should be gray, so you adjust all of the other colors to where the chosen color's R = G = B.

That implementation looks something like this.

const neutral = (whiteColorYouPicked.r + whiteColorYouPicked.b + whiteColorYouPicked.g) / 3.0;

outputColor.r *= neutral / whiteColorYouPicked.r;
outputColor.g *= neutral / whiteColorYouPicked.g;
outputColor.b *= neutral / whiteColorYouPicked.b;

In practice, this can look OK if the original photo hasn't been adjusted in post-processing in any way. I have found many examples where it just doesn't work, though. Possibly due to heavy edits to the colors in the photo or very poor color rendering quality out of the camera.

Giwayume avatar Feb 13 '25 04:02 Giwayume

Also (whiteColorYouPicked.r + whiteColorYouPicked.b + whiteColorYouPicked.g) / 3.0 can be swapped out for a better approximation of gray.

Giwayume avatar Feb 13 '25 16:02 Giwayume