Sunday, June 28, 2009

Correct Color Cast, Using Levels and Curves

This tutorial is done in Gimp 2.6.1. If you are using a different version you may face several differences in menu locations or tools panels.

If you don't know what a color cast means please check Wikipedia or any source you want. Basically it means that the photography presents an unwanted unbalance between RBG channels (red, green and blue colors).

There are more possibilities to correct color cast but I will present here just my favorite methods, using Levels and Curves tools.

The first method, using levels, work only in case you have a photo with neutral gray points (neutral mid-tones). A perfect neutral gray point is a pixel having 50% values on each color channel.

The first part presented will be common to both approaches. This is the original image (I don not remember the link, but it's freely available from http://gimp-savvy.com):


Wow, we have some blue in this photo isn't it? In order to perform color cast corrections we need 3 points from our image: black, white and a neutral. With the second method (curves) you can use more points in order to fine tune final result.

For this photo it is relatively easy to detect 3 reasonable points, but I what to use a fine tunned way which will help you also with more complicated situations and which does not counts on the way your monitor displays the colors. In order to do this we will use the threshold tool.

We will duplicate the background layer, using the Layer menu (Layer -> Duplicate Layer), right clicking on the layer in Layers dialog and selecting Duplicate Layer, clicking the Duplicate Layer button on the layers dialog or using the shortcut: Shift + Ctrl + D.


We will use this layer to help us in selecting the black (shadow) point:
  1. Select the Background copy layer;
  2. Open the Threshod tool;
  3. Make sure the Preview is checked;
  4. Move both sliders to 0 (to the left, or enter 0 in both text boxes);
  5. Move the white slider to the right until a useful amount of white pixels are displayed in the image;
  6. Click Ok to apply and close the threshold tool.

Now, in the image window, click on the above ruler and drag down until crosses over a white zone. Now click on the left ruler and drag right until intersects the previous line over the white zone (CLICK on image below).


After that, in case we plan to use the curves tool, we will insert a sample point on the intersection. Keep Ctrl presses while clicking on any of the rules area (top or left) and drag over the intersection of the guide lines. If you do not have open the sample points dialog, you can activate it from Windows - > Dockable Dialogs -> Sample Points. Make sure the sample point indicates 255 for red, green and blue, which indicates that you really selected a white spot in the image.


At this point you can delete the copy layer on which we worked until now. As the background layer becomes selected the sample points indicates the corresponding values from this layer. I use sample points because I consider that are really helpful when making corrections using the curves tool. For levels adjustments, this points are not needed (actually better don't have them).


We will do the same operations for the white (bright) point:
  1. Duplicate the background layer;
  2. Select the Background copy layer;
  3. Open the Threshold tool;
  4. Make sure the Preview is checked;
  5. Move both sliders to 255 (to the right, or enter 255 in both text boxes);
  6. Move the black slider to the left until a useful amount of white pixels are displayed in the image (in this case are enough pixels at 255, no move is needed);
  7. Click Ok to apply and close the threshold tool;
  8. Choose a white point and drag horizontal and vertical guide lines from rules which should intersect over that point.
  9. Place a sample point (keep Ctrl pressed while clicking on the ruler, than drag the sample point over the guide lines intersection);
  10. Delete or hide the copy layer.
We need only one more point, the neutral mid-tone. This is the most difficult to be spotted in the image. Usually good candidates for this are white surfaces which are not in the light direction. We will use the threshold tool for this also but we have to do a trick before. We will use a gray layer and we will set the mode to Difference for it. This mode subtracts the pixel value of the upper layer from that of the lower layer and then takes the absolute value of the result. Since the upper layer is gray, all pixels have 128 value. If the below layer has perfect neutral points the result will be 0 (black). We do not expect however such perfect pixels, we are looking for anomalies wright? We will look for darken pixels on areas we know that are in reality white (but not under direct light exposure).
  1. Duplicate the background layer;
  2. Click on the foreground color on the toolbox window. In the color dialog enter 128 value for red, green and blue. Click Ok. Your foreground color should be gray now.
  3. Create a new layer and choose foreground color for layer fill type;
  4. In layers dialog make sure the new layer is selected and change mode to Difference.
  5. Merge down this layer. With the layer selected right click on the layer an choose Merge down, or go to Layers menu and choose Merge down;
  6. Select the layer resulted after merge;
  7. Open the Threshod tool;
  8. Make sure the Preview is checked;
  9. Move both sliders to 0 (to the left, or enter 0 in both text boxes);
  10. Move the white slider to the right until a useful amount of white pixels are displayed in the image (we need more pixels than for black points because we have anomalies);
  11. Click Ok to apply and close the threshold tool;
  12. Reduce the layer opacity as needed to distinguish the picture elements. From the white points choose one which is in a neutral area (gray or a white surface not under light). I think that bout is white right?;
  13. Choose a white point (did you noticed the front part of the boat, between the two guys? It matches out thresholded layer) and drag horizontal and vertical guide lines from rules which should intersect over that point.
  14. Place a sample point (keep Ctrl pressed while clicking on the ruler, thad drag the sample point over the guide lines intersection);
  15. Delete or hide the copy layer.


After deleting (hiding) all other layers except background, make sure the background is selected and take a look at the sample points dialog. You should have 3 points there: black (shadow), white (highlight) and mid-tone neutral.


Look at those points. Something is wrong, except for white. We have a small deviation at the black point, but the neutral one is completely out of scope. We expected almost equal values for all channels at this point. Also this values should be close to 128 (50%). It's time for as to change this mess.

Unfortunately, Gimp doesn't allow us to select a sample point with the eye-dropper. In order to get rid of this constrain, click near the sample point, keep the mouse button down and drag the dropper inside the sample point. Those guide lines will help us to select the proper pixel values because near an intersection we will receive the proper pixel, although we are a little bit out of scope with the cursor. It is really difficult to select a pixel with the right values for a sample point. In conclusion, when working with levels tool, the guiding lines will help us. When working with curves, both guiding lines and sample points are useful. We will see this later.

Since we have a neutral point available, we can use the Levels tool. We are interested in those three eye-droppers at the right of the Auto button. From left to right those droppers are for black, neutral and white points. Click on the left one, click near sample point 1, keep the mouse button down and drag the picker inside the sample point 1. Now click the most right picker and do the same for sample point 2. An finally select the middle picker do the same with sample point 3 and enjoy the result.


We were lucky, we had that magic point, but what if.... we haven't? Well... in this case the levels tool is not so useful anymore. We have to use the curves tool. With this one you can experiment with more points you think that might be of a specific color. Feel free to experiment until you are satisfied by the result (this method is called perturbation).

For this tutorial we will use only the same 3 points as for levels tool. Open the curves tool. Ctrl+Click near each sample point, then drag inside the sample point. This will create 3 control points in the curves tool for each channel.


Let's look again at those 3 sample points.

The first one should be black. OK, I admit I do not need really 0 there, but a 10 on each color should be better than what I have. The second one is perfect, truly white, no change needed. The last one is ... well... far away... What values to put here? In a perfect move, if this is really a perfect neutral point, I need 128 on each color. I'll give it a try. If you will meet point with 2 colors nearly equal than probably the 3rd one should also be the same. If you are not satisfied with result you should try different variations. Tray to move all the others colors to the value of one. Try e median one. Try to use other points also. Try all you can until satisfied.

Having this sample points values displayed all the time helps me moving than control points. Let' start with the red channel first. As I said I will try 10 for the black, I'll leave the white as it is and I will try 128 for neutral. I gave to make 2 changes in this channel: X:29 Y:10 and X:109 Y:128.


For the green channel: X:27 Y:10, X:118 Y:128.

And finally the blue channel: X:32 Y:10 and X:149 Y:128.

Yes, we finished, here is the result:
Let's review,
Original image:
Levels tool correction:
Curves tool correction:

I hope you enjoyed this tutorial and see you soon.
By the way do you not that The Gimp is completely free of cost and it runs under Linux, Mac OS X and Windows, right?

8 comments:

Paul said...

Excellent tutorial, thanks!

rosty said...

I am glad you like it, since this is my first tutorial, your comment really motivates me to write the next one.

boromil said...

very nice tutorial.

Anonymous said...

Very useful!

turnster said...

Excellent! Looking forward to your next tutorials.

Anonymous said...

yes, is very useful

Anonymous said...

Your first?!
It looks like a professional one! Congrats! Keep them coming! ;-)

Anonymous said...

Very good tut. Useful to know.

Post a Comment