Program(s): PSP 7+, GIMP, Photoshop Elements.
Involves: In-depth explanation of how Levels and Curves work, covering:
- What an image histogram is, and how to read one
- The principles behind transformation tools such as Levels and Curves
- How to use the Levels tool
- How to use PSP's Histogram Adjustment tool
- How to use the Curves tool
Translatable: Advice should be translatable to pretty much any program.
Steps: This a general guide rather than a step-by-step tutorial.
Difficulty: Medium. Requires knowledge of basic icon-making and where to find tools.
SO WHAT'S A HISTOGRAM?
Every pixel in a digital image has a grey value somewhere between 0 (black) and 255 (white) that determines how dark it is. The image histogram is like a graph of how much of each shade of grey there is in the picture. You can view the graph for the currently selected image by opening the histogram window:
GIMP - Dialogues > Histogram
PSP 7 - View > Toolbars > Histogram Window
PSP 8 - View > Palettes > Histogram
Elements - Windows > Histogram
The shape of the histogram will tell you a lot about the overall appearance of the image and what kind of correction it needs. I'm using black and white images so it's easier to see the grey values at a glance, but it works just the same for colour pictures.
This cap is pretty dark, so the histogram is squashed over on the left. All the grey values are close to 0 (black) and there's nothing at all up the lighter end of the graph.
This one, on the other hand, has a big peak up the light end thanks to all that snow, but no dark shades. The peak isn't all the way over to the right because it's not actually pure white, just pale grey.
This image has a lot of middle grey, but no really light or dark shades. That's why it looks so dull and low contrast.
Whereas this one has all the shades from 0-255 represented. You can see it has far better contrast than any of the others.
Okay, so looking at the histogram of an image allows you to identify brightness and contrast problems. But how do you fix them?
The problem with just using the basic Brightness/Contrast tool is that it affects every shade of grey in the image at the same time. That means that if you want to make the highlights lighter, the shadows are made lighter too. If you want to increase the contrast between two very similar shades, everything else gets ultra-contrasted too. So you usually end up with a compromise image with weak shadows and nasty 'shiny' highlights.
What you really need are tools that can treat different shades of grey differently. Then you can specify that you only want the highlights to be brightened and not the shadows, or that you only want a contrast adjustment to be applied to the midtones. You can fix the things that need fixing without screwing up the rest of the image in the process.
For that, you need tools like Levels and Curves. Here's a quick example of the difference they can make:
OriginalB/CLevelsCurves
As you can see, the results look much better than just using Brightness/Contrast. But because these tools do more complicated things, they're a lot less intuitive to use. A little bit of background explanation might be helpful.
TRANSFORMATION GRAPHS
With a simple change like increasing the brightness, it's easy to predict what will happen to the image. Every shade of grey is brightened by the same amount, so you could just write it as an equation like this:
[Final Grey Value] = [Original Grey Value] + 10
But if you're applying a more complicated change, different things will happen to different shades of grey. You'd need to keep track of what happens to each individual shade, and the simplest way to do that is to make a lookup table: a long list that tells you that when you put this value in, you get this value out. Like so:
Input ValueOutput Value
0 0
1 3
2 7
... ...
Of course, with 256 possible shades of grey, that's going to be one massively long table. There's no way you could picture what's happening to the image just from looking at the numbers. So instead of leaving it in table form, we plot those pairs of Input/Output values on a graph, like this one:
This is actually two graphs laid on top of each other. The histogram is there as a guide to the shades of grey that you have in the original picture. The Input/Output graph is that diagonal line running over the top of it.
This particular line represents "no change". It runs from (0,0) up to (255,255) in a straight line, so at every point along that line, Input and Output are identical. If you applied that change to your starting image, nothing would happen.
Whenever you see a diagonal line running from the bottom left to the top right on a histogram tool, it means it's on the default setting and no changes have been made yet.
Setting the Black and White Points
You'll see on the graph above that although it has output values plotted for every input from 0-255, the actual histogram doesn't contain all those shades. The darkest shade in this image is about 50, and the lightest about 185. So why do we have outputs plotted for values outside that range? It's kind of pointless.
It would be better to move the start of the line to the point (50,0) - to say that a value of 50 in gives a value of 0 out. That means that after you apply the change, the darkest pixels on your starting image (currently shade 50, a sort of charcoal grey) will be converted to black.
You can do the same at the other end of the line. If we move the end point to (185,255), then the lightest pixels on the starting image (originally only shade 185, which is rather dull) will come out as 255, true white. All the values between 50 and 185 will be spaced out evenly between black and white.
So now your Input/Output graph looks like this:
...And your picture goes from this:
to this:
That's already made a major improvement, but there's plenty more we can do.
Setting Curves
As it stands, we've altered where the line starts and ends, but it's still a straight line. That means all the grey values in that 50-185 range are being treated exactly the same. But what happens if we put a curve in the graph? Say we drag the line down a little, like this:
Okay, so let's look at that a minute.
The line still starts and ends at the same points, so the black and white values will be the same. But now the line is lower down, and on the output axis, down means closer to 0 (black) - so the output picture will be darker. The change from the original straight line is greatest towards the middle and least at the two ends, so that means this adjustment will affect the middle greys more strongly than the shadows or the highlights.
The result of changing the line to a downward curve looks like this:
to
What if we curve the line the opposite way?
If the line has moved up, it's got closer to 255 (white) on the output axis - so the output picture will be lighter. Again, the curve is furthest away from the original line towards the middle, so the middle greys will be lightened the most.
The result looks like this:
to
Depending on the tools you use, you can make any number of different lines and curves, but I'll just do one more example. This is a type of curve that's often used to improve contrast, called an s-curve:
As you can see, just like the letter S it's actually two curves going in opposite directions: one dragging the bottom half of the line down, and another one dragging the top half up. That means that all the darker shades get darker, and all the lighter shades get lighter. It makes a dramatic improvement in contrast without wrecking the shadows and highlights:
to
Okay, so that's what histogram adjustments can achieve, but how do you make them? There are several tools, but sadly they're not all available in all programs.
HISTOGRAM TOOLS
Levels
Availability: GIMP - Yes | PSP - Yes | Elements - Yes
Levels is the simplest of the tools, and it's fairly easy to get to grips with even if you know nothing about curves.
The dialog has three input sliders. The left and right sliders are for setting the black and white points, and the middle one is for gamma correction. The gamma has a default value of 1. If you reduce it, that's the equivalent of dragging the curve down: the image gets darker, with the midtones being affected the most. If you increase it, that's dragging the curve upwards: the image gets lighter, again affecting the midtones the most.
Tips:
- Always leave the output levels set at 0 and 255. If you decrease that range, you're decreasing the contrast of your output image.
- Use RGB mode to alter the overall brightness and contrast of the image. On a colour image, you can also select the individual Red, Green and Blue channels to affect the level of that colour in each pixel instead of the amount of grey.
- Don't overdo the gamma correction. It's quite a strong effect, and most images will be okay with it left at 1.00 or very near to it.
Histogram Adjustment
Availability: GIMP - No | PSP - Yes | Elements - No
This is a user-friendly Paint Shop Pro tool that's like a simplified version of Curves. It has all the same controls you get with Levels, plus an extra slider on the right that you can use make s-curves, and a display window that shows you the shape of the curve you've created.
Unfortunately, Histogram Adjustment is difficult to use on colour images because it doesn't have an RGB mode. The luminance mode is brilliant for greyscale, but if you use the colours mode you have to make adjustments to the Red, Green and Blue channels individually, which takes longer and makes it easy to mess up your colour balance.
Tips:
- As with Levels, leave the output min and max at 0 and 255, or you'll limit the contrast.
- Don't use luminance mode on colour images. It improves the grey values but leaves the hue and saturation the same as they were in the lower contrast original, so the colours look washed out.
- Expanding the midtones is good, compressing them is bad. An s-curve gives you better contrast; the opposite of an s-curve does the opposite.
Curves
Availability: GIMP - Yes | PSP - Yes | Elements - No
And finally, the best and most difficult of the histogram tools: Curves.
Curves gives you complete freedom, because it allows you to make the line of the graph any shape you like. Click somewhere on the line to create a new point, then either use the mouse to drag it to a new position, or type coordinates for it in the Input and Output boxes. If you want to delete a point, just drag it off the outside edge of the graph.
Here's a quick walkthrough of fixing up an image with curves. I started with this image:
1. First, pick a part on the image that's meant to be pure white (in this case I picked the highlights in her hair). Keep your eyes on that highlight as you drag the upper right point of the curves graph to the left. When your chosen highlight starts to 'spread' you know you've gone too far, so nudge the point back right a little and leave it there.
Curves:
Result:
2. Pick a part of the image that's meant to be black (shadowy folds in clothing are good) and drag the lower left point to the right until it looks dark enough. (You don't have to be quite so exact as you do with the white point, because it's not such a problem if the shadows spread a bit.) This was a darkish screencap anyway, so I only made a small adjustment.
Curves:
Result:
3. Now, stop and study your image. What needs fixing? I thought her face looked a bit flat and could do with being lighter, so I made a new point towards the top of the graph and dragged it up a bit.
Curves:
Result:
4. Now the highlights on her face are bright enough, but the image has lost too much shadow. I made another point close to the bottom of the graph and dragged it down a little to darken the shadows.
Curves:
Result:
5. Looks pretty good now, but I thought the midtones on the face could stand to be a tiny bit brighter to make the contrast more dramatic. So I added another point just above the middle and dragged that up a fraction.
Curves:
Result:
...And that was where I stopped. Notice that all of the curves I used there were quite gentle changes. Subtle works better with this tool.
Other Tips:
- Make sure the line always reaches from the very bottom to the very top of the box to give you the full range of output shades.
- Don't double back on yourself. Every point should be higher than the ones on its left and lower than the ones on its right, or else the colours will be inverted.
- Avoid having sections in the middle of the graph that are close to vertical or horizontal - you get weird solarising or exclusion type effects.
- The steeper the line is, the smaller the curves you can use before it starts to look bad. If your black and white points end up pretty close together, you probably won't be able to do much more in the way of fixing.
And that's a wrap. Sorry this got a little epic, but there's a lot of information to cover. I know some of the image processing stuff is complicated to get to grips with, so if anything's not clear, just ask and I'll see if I can explain it better.