Given a bad balanced RGB image (in terms of white balance), how can I choose the proper color balance that needs to be applyed (as a RGB vector where 128,128,128 is the neutral)?
Same question for a YUV image.
Given a bad balanced RGB image (in terms of white balance), how can I choose the proper color balance that needs to be applyed (as a RGB vector where 128,128,128 is the neutral)?
Same question for a YUV image.
If you have a known white or grey point, you want to calculate the ratio between the colors so that each is given a factor to multiply by. For example, in your 250,245,255 reference it would be 1.02, 1.0625, 1 since multiplying the sampled values for white would produce an actual white. (255,255,255). Since the sensor should be linearly responsive, this same ratio should be consistent for the entire light range.
The exact math may vary a bit though depending on what type of entry your camera takes, but the principal is generally the same that you are trying to adjust the color channel's values by a factor to reach the corrected value.
Given a bad balanced RGB image (in terms of white balance), how can I choose the proper color balance that needs to be applyed (as a RGB vector where 128,128,128 is the neutral)?
The answer is, you can't, at least not without human judgement.
If you have an RGB image with an incorrect white balance, there is no way to detemine what the correct white balance would have been computationally, with the RGB data alone. You would need a human brain that can interpret what's in the image and what areas of it should be white or neutral, from their own experience knowing what colours things should be.
So you can never do this without some level of human guesswork or common sense for each image.
Often the easiest way to do this is to identify an area of the image that should be white or neutral grey, and adjusting the white balance such that that area is pushed towards neutral grey. Image editing programs typically have a tool for doing this. However, if there is nothing that really is neutral grey in that picture, then you will simply have to adjust it by eye based on the un-scientific approach of "what looks right".
If you were present when the picture was taken you could have held a grey card in front of the camera, lit by the same light source as the image you took and with the same white balance setting on-camera. But if you had the ability to do that, you probably also have had the ability to get the white balance right on the day.