# Lightroom Grey card algorithm for white balancing

I am trying to learn grey card algorithm to adjust the image color based on the Grey Card used. From as far this answer I had tried one of my photo:-

Selection color(Grey Card Color) :- 115,168,178

Neutral Color:- 128,128,128

Correction needed:- -13,40,50

I have tried to change the RGB of the image based on that correction using Photoshop & GIMP and Used Lightroom Cutom picker for white balance and Saw both are different.

• For starters, the signs on your corrections are wrong. – Blrfl Jul 28 '17 at 10:36
• Sorry. Did not got your point. – Bik Jul 28 '17 at 10:40
• Could you please give me some reference from where I can understand the White balancing logic. – Bik Jul 28 '17 at 10:44
• web.stanford.edu/~sujason/ColorBalancing try this site – dannemp Jul 28 '17 at 12:10

Three possible problems with your procedure.

1. Neutral is NOT defined as 128,128,128. Neutral is equal RGB. 207,207,207 is Neutral. 69,69,69 is Neutral. Any equal RGB tones is Neutral (no color cast). And the 18% gray card is NOT 128,128,128. It is 18%, but gamma does raise it in our images, but it will still be a little lower than 128.

You are subtracting from 128, which is wrong concept. If you know the spot should be neutral, you should be trying to make the RGB be equal tones, whatever they are. Neutral is equal RGB, but not necessarily at 128. The difference from 128 is brightness (and is adjustable). The difference from equal RGB (of a neutral color) is a color cast.

1. The usual and normal and easy procedure is to use a White Balance tool to click on the color that we know should be neutral, and then the computer program makes it be neutral. Adobe Raw has such a WB tool, and the Photoshop Levels middle gray eyedropper does it as well.

2. 18% gray cards are usually approximately neutral, but are not manufactured to insure neutral. They "work", but they are too dark to be best. Instead, they try to insure 18% reflectance, which is not your goal.

So instead, get a real actual White Balance card, made for the purpose. These are lighter gray color, and good ones are white. WhiBal is a very good brand card. I prefer the Porta Brace White Balance card (\$5 B&H)

http://www.scantips.com/lights/whitebalance.html

• Could you please let me know how can I get the neutralized color. – Bik Jul 31 '17 at 6:55
• I just mentioned the WhiBal brand or Porta Brace brand white balance card.(B&H, Adorama, Newegg, or probably Ebay). Use one of them instead of the gray card, they are neutral. Then use a photo editor with a White Balance Tool to just click it. Adobe Elements or Photoshop has the camera raw WB tool, or Lightroom has it. Even Picasa will do it.Several other editors have it, but several do not. scantips.com/lights/whitebalance.html – WayneF Jul 31 '17 at 14:26
• I am trying to implement the White Balance tool with Eye dropper using Javascript and The grey card with neutral color are not same on the image, Lightroom use some algorithm to neutral that color. – Bik Aug 1 '17 at 5:34

There are a number of ways to do such a conversion. I'm assuming you want the user to be able to choose a color that should be neutral in the image, but is not.

My guess for Lightroom is that they probably convert the RGB values into the Lab color space, then adjust the `a` and `b` values of each pixel by a particular amount. (The amount being the difference between the original color and a zero value for `a` and `b`.) You would probably want to skew the L axis of the entire color space so that the chosen color lines up with where `a` and `b` are 0 in the unskewed space.

You can approximate such a change in other ways. One way is to convert from RGB to something simpler like Y'CbCr, and adjust your colors there. Again, you'd skew the Y' axis so that the color the user originally chose is moved in its plane to the origin (where Cb and Cr are 0).

You can mimic this in straight RGB by rotating the gray axis (r=g=b) to be vertical, skewing this new vertical axis so that the chosen color ends up on the axis, and then rotating by the reverse of the first rotation.

• Could you please let me know how can I get the neutralized color. – Bik Jul 31 '17 at 6:55
• When you're in the other color space (either Lab or Y'CbCr), you simply set the a and b color channels (or Cb and Cr color channels) to 0, so that you have only luminance. That will give you the neutral equivalent of the color you chose in the original image. – user1118321 Jul 31 '17 at 15:55