This question got me very close to my answer, but I'm looking for more precision: What is the math behind white-balance, and how to choose it?
I have an image with white, grey, and black color cards in the background and I would like to white balance my image (using math rather than an "auto" button from a photo editing software.
In my image, the white card has RGB values of (181, 176, 141) and the black card has values of (64, 61, 38).
If I follow the answer from the question I linked above then I would adjust the pixels by (255/181, 255/176, 255/141) to make the white card actually white (255). But this would turn the black card into (90, 88, 69) rather than (0, 0, 0).
So my question is, what is the best mathematical adjustment to use to correct for both the black and white cards. I have not used the grey card yet, but adjusting to match it would be good too. Again, I'm looking for the mathematical adjustment since I'm trying to do this in a rigorous scientific way. Identical white balance correction between all my images is very important.
Here's an example image if it's helpful. Note that the glare from the overhead light will not be present in the pictures I actually care about.