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.

Am I doing something wrong? Please help me on this.

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

2 Answers 2


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)


  • \$\begingroup\$ Could you please let me know how can I get the neutralized color. \$\endgroup\$
    – Bik
    Jul 31, 2017 at 6:55
  • \$\begingroup\$ 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 \$\endgroup\$
    – WayneF
    Jul 31, 2017 at 14:26
  • \$\begingroup\$ 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. \$\endgroup\$
    – Bik
    Aug 1, 2017 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.

  • \$\begingroup\$ Could you please let me know how can I get the neutralized color. \$\endgroup\$
    – Bik
    Jul 31, 2017 at 6:55
  • \$\begingroup\$ 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. \$\endgroup\$ Jul 31, 2017 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.