- Joined
- Mar 8, 2011
- Messages
- 25,202
- Reaction score
- 9,036
- Location
- Iowa
- Website
- pixels.com
- Can others edit my Photos
- Photos NOT OK to edit
Demystifying Histograms
Even though I’ve only been on the forum for less than two years, I’ve noticed that there has been very little discussion about one of the most useful tools for the digital photographer. And that’s a subject of histograms.
So to rectify that situation, I’m going to create a tutorial that will hopefully explain what a histogram is and how to properly use it.
I’m going to break down the subject into five sections:
1. The basics
2. Sample histograms using geometric shapes & colors
3. Different types of histograms (luminance v. RGB)
4. Using histograms in-camera
5. Using histograms in post
-----------------------------------------------
1. The basics
Histograms are basically bar charts based on the brightness of the various pixels in a photograph. Once constant that is true with all histograms is the dark portion of the image is on the left of the chart, and the light areas are on the right. This is true no matter what camera or software you use.
The following is a graphic representation of all 256 shades of gray that are available in digital photography:
Pure black, represented by 0 on the left, is not dark gray… it is black. Pure white, represented by 255 on the right, contains not even the slightest hint of gray.
What the software in your camera (or post software) does is look at the brightness of each pixel, then places that information in the bar graph depending on how ‘bright’ the pixel is. If a pixel is very dark, say, 5 or 10, it will be counted on the far left of the histogram. If it is bright, say 245 or 250, it will be counted on the right end of the graph.
-----------------------------------------------
2. Sample Histograms using shapes & colors
A histogram of an image that contains nothing but ‘middle gray’ (128) will look like this:
Notice the spike in the middle of the graph. This means all the pixels are the same color, and they are in the middle of the 0-255 scale.
Let’s make the gray darker and see what happens to the histogram.
Notice how the spike, or line, moves to the left. This means the pixels are darker now.
So let’s see what a blend of grays look like. I spread the shades of gray between 64 and 192 horizontally across the ‘image’.
The histogram now shows there are no pixels with a brightness lower than 64, none brighter than 192, and the remaining pixels are roughly divided equally across the image. This is because the blend was done horizontally, from left to right.
Now for some thinking on your part. Suppose I were to blend the grays from bottom left to top right. This means there would only be a few pixels with the darkest gray, and the number of pixels would rise across the histogram until the blend of grays reached the top left corner. This is because the shades of gray that are perpendicular to the direction of blend should be equal. Then the counts should level off until the blend reaches the bottom right. At this point, the counts should taper off. Make sense?
So let’s see if the histogram bears this out.
Looking at the histogram from left to right, we see no pixels until we reach 64. Then the count starts to rise. Then the pixel counts remain the same, and finally drop off as the lighter shades of gray diminish into the top right. Then the pixel counts are zero from 192 to 255.
The purpose of this part of the tutorial is to get you to understand how the histogram is ‘built’. The orientation of the image (portrait or landscape) is not relevant, nor is the aspect ratio of the image.
Now I’m going to throw in a couple areas of dark and light gray.
I put in a circle of light gray (NOT white), and dark gray (Not black). As you can see in the histogram, the light gray circle shows up as a spike on the right side of the histogram, and the dark gray square is counted by the spike on the left. Note also, the two dips in the center part of the histogram. This is caused by those areas now covered by the circle and the square. Make sense?
So far, I’ve dealt only with shades of gray. How dull our world would be without color. So let’s add some color!
Let’s take the gray image, and divide into three sections. I’ll blend, from bottom left to top right, dark red / medium green / light blue into each section.
To show you how the histogram represents the pixel count of the image, I’ll add some arrows.
Don’t worry about the colors in the histogram not matching the colors in the image. They’re not intended to do that. All they are intended to do is give you an idea of the pixel counts based on brightness and color.
Hopefully, what you've read so far will help you understand how a histogram is ‘built’, using the brightness of the individual pixels, to create a bar chart.
-----------------------------------------------
3. Different Types of Histograms
There’s basically two flavors of histograms: Luminance and RGB.
With a luminance histogram, only the brightness of the pixels are considered. So a sample histogram might look like this:
While an RGB histogram is ‘built three times’, once counting the red pixels, once counting the green, and the third counting the blue pixels.
So take an ordinary image taken with your camera, and the histogram will look like this:
Notice all the dark blue in the building in the background, and you can see it shows up as the tall spikes on the left of the histogram. The bright red portion of the sculpture shows up on the right. The medium-green grass is spread out all across the histogram. And the dark yellow of the sculpture can also be ‘seen’ in the histogram.
-----------------------------------------------
4. Using Histograms in your Camera.
The vast majority of digital cameras today have the capability of displaying the histogram of the image displayed on the monitor. This is a valuable tool that can be employed in the field to ensure proper exposure. It should be noted that camera monitors are terrible when you look at just the image to judge whether you’ve ‘nailed’ the exposure. Looking at the histogram, however, can give you the information you need to determine whether the image has been exposed correctly. The brightness setting of the monitor can also effect what the image ‘looks like’.
For instance, let’s say you’re out shooting a snowy scene on a sunny day. Your eye’s pupils will be closed because of the bright sunlight reflecting off the white snow. You take a shot, and look at it on the camera’s monitor. It may look just perfect.
But then you get home and load the image into your computer. You find you grossly overexposed the shot, and you end up with this:
You can quickly see by the histogram alone that the image is horribly over-exposed. All the pixels are ‘piled up’ along the right side of the histogram. And there’s very few, if any at all, on the left. So you end up with a bunch of snow that’s totally ‘blown out’, meaning it is pure white and contains no detail.
But suppose you get into the habit of looking at the image’s histogram on the camera’s monitor when you’re out shooting. This over-exposure would be easily prevented. You ignore what the image looks like in terms of exposure when looking at the monitor. You rely instead on the histogram you see. So when you get back to your computer, you’d find what your eye & mind saw earlier:
The goal in the field is to use the histogram to judge whether or not the exposure is correct, NOT the image displayed. If you were to see the histogram all piled up on the right, then you know you’re overexposed and need to correct the problem now while you still have the chance.
The same holds true at the other end of the scale. Trying to take a ‘low-key’ image in a dark room causes your pupils to dilate, and the image can look too bright so you end up underexposing it instead.
Nothing is more disappointing that to find you ‘missed the shot’ because of something that could be easily prevented in the field. So in this case, you check the histogram and it shows you the image is severely underexposed. See all the pixels piled up on the left? Since you’re in the habit of checking the in-camera histogram, you can quickly remedy the error and produce the image you want!
It's not important what the 'shape' of the histogram is. There is no 'ideal' shape. What IS important it to try to keep the image from being so underexposed the histograms starts to 'pile up' on the left, or overexposed and the histogram 'piles up' on the right. In the former case, the dark areas in your image will end up with no data at all, be rendered completely black and you'll end up with no details. In the latter case, the highlights would be blown out, be pure white, and have no details as well.
-----------------------------------------------
5. Using Histograms in Post Processing
Remember the hucksters on the late-night advertisements on TV: “But wait! There’s more!”? Getting a properly exposed image is only part of the process. It continues through to your computer, where you spit-n-polish your image into a real wall-hanger.
Suppose you take an image and you’re happy with the exposure, but it just doesn’t look right. You may say it ‘looks flat’, or ‘it’s dull’, or ‘it just isn’t crisp’. You want it ‘to pop!’ The issue may be your camera’s dynamic range is far greater than the dynamic range of the scene you captured.
Here’s an example:
Kinda dull, isn’t it? Why? Because there’s no real dark and light areas. It lacks contrast. We expect to see blacks and whites. So let’s look at the histogram of the image:
Yep. Just as you thought! There’s no real dark and light areas in the image. So now it’s time to learn how to ‘set’ the white and black points on the image.
The idea here is to get the histogram to ‘stretch out’ and cover the entire graph area. Now, you could do this with the contrast slider in your software, but that causes a problem.
When you try to stretch the histogram out, you start to ‘comb’ it. Sections of the histogram aren’t filled because of the process. You end up with a histogram with lines in it:
This means you’ll end up with artifacts called ‘banding’ in the image. If you tried to enlarge this image up to a wall-hanger, this banding would become evident. Instead of smooth transitions between similar colors and levels of brightness/darkness, the transitions become rougher and obvious. The solution? Don’t try to fit the histogram to the graph….. make the graph fit the histogram!
To do this, you need to use the Curves tool of your editing software. Where it is, and how to activate differs for each one, but the Curves tool is very common and should be easy to find.
Now, how to adjust the black and white point of an image will also vary depending on your software. But the idea is the same: Bring the left end of the histogram to the right, and the right side of the histogram to the left. With my software, this is done with the little triangles at the bottom of the Curves box. AFAIK, most Curves have a diagonal line overlaying the image’s histogram.
To adjust the black & white points, I need to move the left triangle to the right, and the right triangle to the left. This is how Capture NX2 is done. With GIMP, I would have to 'grab' the dots at the end of the diagonal line (move the bottom left of the line to the right, and the top right of the line to the left). So you'll need to read your software's instructions to find out what you need to do and how to move the points.
OK, so you’re probably thinking, “Yeah, but how far do I move them?” The answer is in the histogram! You want to move the points until you get into where the histogram says the pixel counts start to rise. I’ve marked those spots in the screenshot above with green. So I would just move the black point (the triangle on the left) and drag it until it’s under where I marked in green. I would repeat the process with the white point, moving it to the left until I get to the ‘end’ of the histogram.
The result is this:
I now have a nice, contrasty image that’s no longer ‘flat’ or ‘dull’, and I haven’t created any banding in the image (Take THAT, all you ‘get it right in the camera’ fanatics!)
-----------------------------------------------
So… that’s about it. Hopefully, you’ve learned how to incorporate histograms into both your field and post work, how they work, what they tell you, and how to adjust your exposure and Curves to get the shot you really had in mind!
If anyone has any suggestions or ideas on how to improve on this tutorial, just sing out!
Go forth and actuate!
Ken
Even though I’ve only been on the forum for less than two years, I’ve noticed that there has been very little discussion about one of the most useful tools for the digital photographer. And that’s a subject of histograms.
So to rectify that situation, I’m going to create a tutorial that will hopefully explain what a histogram is and how to properly use it.
I’m going to break down the subject into five sections:
1. The basics
2. Sample histograms using geometric shapes & colors
3. Different types of histograms (luminance v. RGB)
4. Using histograms in-camera
5. Using histograms in post
-----------------------------------------------
1. The basics
Histograms are basically bar charts based on the brightness of the various pixels in a photograph. Once constant that is true with all histograms is the dark portion of the image is on the left of the chart, and the light areas are on the right. This is true no matter what camera or software you use.
The following is a graphic representation of all 256 shades of gray that are available in digital photography:
Pure black, represented by 0 on the left, is not dark gray… it is black. Pure white, represented by 255 on the right, contains not even the slightest hint of gray.
What the software in your camera (or post software) does is look at the brightness of each pixel, then places that information in the bar graph depending on how ‘bright’ the pixel is. If a pixel is very dark, say, 5 or 10, it will be counted on the far left of the histogram. If it is bright, say 245 or 250, it will be counted on the right end of the graph.
-----------------------------------------------
2. Sample Histograms using shapes & colors
A histogram of an image that contains nothing but ‘middle gray’ (128) will look like this:
Notice the spike in the middle of the graph. This means all the pixels are the same color, and they are in the middle of the 0-255 scale.
Let’s make the gray darker and see what happens to the histogram.
Notice how the spike, or line, moves to the left. This means the pixels are darker now.
So let’s see what a blend of grays look like. I spread the shades of gray between 64 and 192 horizontally across the ‘image’.
The histogram now shows there are no pixels with a brightness lower than 64, none brighter than 192, and the remaining pixels are roughly divided equally across the image. This is because the blend was done horizontally, from left to right.
Now for some thinking on your part. Suppose I were to blend the grays from bottom left to top right. This means there would only be a few pixels with the darkest gray, and the number of pixels would rise across the histogram until the blend of grays reached the top left corner. This is because the shades of gray that are perpendicular to the direction of blend should be equal. Then the counts should level off until the blend reaches the bottom right. At this point, the counts should taper off. Make sense?
So let’s see if the histogram bears this out.
Looking at the histogram from left to right, we see no pixels until we reach 64. Then the count starts to rise. Then the pixel counts remain the same, and finally drop off as the lighter shades of gray diminish into the top right. Then the pixel counts are zero from 192 to 255.
The purpose of this part of the tutorial is to get you to understand how the histogram is ‘built’. The orientation of the image (portrait or landscape) is not relevant, nor is the aspect ratio of the image.
Now I’m going to throw in a couple areas of dark and light gray.
I put in a circle of light gray (NOT white), and dark gray (Not black). As you can see in the histogram, the light gray circle shows up as a spike on the right side of the histogram, and the dark gray square is counted by the spike on the left. Note also, the two dips in the center part of the histogram. This is caused by those areas now covered by the circle and the square. Make sense?
So far, I’ve dealt only with shades of gray. How dull our world would be without color. So let’s add some color!
Let’s take the gray image, and divide into three sections. I’ll blend, from bottom left to top right, dark red / medium green / light blue into each section.
To show you how the histogram represents the pixel count of the image, I’ll add some arrows.
Don’t worry about the colors in the histogram not matching the colors in the image. They’re not intended to do that. All they are intended to do is give you an idea of the pixel counts based on brightness and color.
Hopefully, what you've read so far will help you understand how a histogram is ‘built’, using the brightness of the individual pixels, to create a bar chart.
-----------------------------------------------
3. Different Types of Histograms
There’s basically two flavors of histograms: Luminance and RGB.
With a luminance histogram, only the brightness of the pixels are considered. So a sample histogram might look like this:
While an RGB histogram is ‘built three times’, once counting the red pixels, once counting the green, and the third counting the blue pixels.
So take an ordinary image taken with your camera, and the histogram will look like this:
Notice all the dark blue in the building in the background, and you can see it shows up as the tall spikes on the left of the histogram. The bright red portion of the sculpture shows up on the right. The medium-green grass is spread out all across the histogram. And the dark yellow of the sculpture can also be ‘seen’ in the histogram.
-----------------------------------------------
4. Using Histograms in your Camera.
The vast majority of digital cameras today have the capability of displaying the histogram of the image displayed on the monitor. This is a valuable tool that can be employed in the field to ensure proper exposure. It should be noted that camera monitors are terrible when you look at just the image to judge whether you’ve ‘nailed’ the exposure. Looking at the histogram, however, can give you the information you need to determine whether the image has been exposed correctly. The brightness setting of the monitor can also effect what the image ‘looks like’.
For instance, let’s say you’re out shooting a snowy scene on a sunny day. Your eye’s pupils will be closed because of the bright sunlight reflecting off the white snow. You take a shot, and look at it on the camera’s monitor. It may look just perfect.
But then you get home and load the image into your computer. You find you grossly overexposed the shot, and you end up with this:
You can quickly see by the histogram alone that the image is horribly over-exposed. All the pixels are ‘piled up’ along the right side of the histogram. And there’s very few, if any at all, on the left. So you end up with a bunch of snow that’s totally ‘blown out’, meaning it is pure white and contains no detail.
But suppose you get into the habit of looking at the image’s histogram on the camera’s monitor when you’re out shooting. This over-exposure would be easily prevented. You ignore what the image looks like in terms of exposure when looking at the monitor. You rely instead on the histogram you see. So when you get back to your computer, you’d find what your eye & mind saw earlier:
The goal in the field is to use the histogram to judge whether or not the exposure is correct, NOT the image displayed. If you were to see the histogram all piled up on the right, then you know you’re overexposed and need to correct the problem now while you still have the chance.
The same holds true at the other end of the scale. Trying to take a ‘low-key’ image in a dark room causes your pupils to dilate, and the image can look too bright so you end up underexposing it instead.
Nothing is more disappointing that to find you ‘missed the shot’ because of something that could be easily prevented in the field. So in this case, you check the histogram and it shows you the image is severely underexposed. See all the pixels piled up on the left? Since you’re in the habit of checking the in-camera histogram, you can quickly remedy the error and produce the image you want!
It's not important what the 'shape' of the histogram is. There is no 'ideal' shape. What IS important it to try to keep the image from being so underexposed the histograms starts to 'pile up' on the left, or overexposed and the histogram 'piles up' on the right. In the former case, the dark areas in your image will end up with no data at all, be rendered completely black and you'll end up with no details. In the latter case, the highlights would be blown out, be pure white, and have no details as well.
-----------------------------------------------
5. Using Histograms in Post Processing
Remember the hucksters on the late-night advertisements on TV: “But wait! There’s more!”? Getting a properly exposed image is only part of the process. It continues through to your computer, where you spit-n-polish your image into a real wall-hanger.
Suppose you take an image and you’re happy with the exposure, but it just doesn’t look right. You may say it ‘looks flat’, or ‘it’s dull’, or ‘it just isn’t crisp’. You want it ‘to pop!’ The issue may be your camera’s dynamic range is far greater than the dynamic range of the scene you captured.
Here’s an example:
Kinda dull, isn’t it? Why? Because there’s no real dark and light areas. It lacks contrast. We expect to see blacks and whites. So let’s look at the histogram of the image:
Yep. Just as you thought! There’s no real dark and light areas in the image. So now it’s time to learn how to ‘set’ the white and black points on the image.
The idea here is to get the histogram to ‘stretch out’ and cover the entire graph area. Now, you could do this with the contrast slider in your software, but that causes a problem.
When you try to stretch the histogram out, you start to ‘comb’ it. Sections of the histogram aren’t filled because of the process. You end up with a histogram with lines in it:
This means you’ll end up with artifacts called ‘banding’ in the image. If you tried to enlarge this image up to a wall-hanger, this banding would become evident. Instead of smooth transitions between similar colors and levels of brightness/darkness, the transitions become rougher and obvious. The solution? Don’t try to fit the histogram to the graph….. make the graph fit the histogram!
To do this, you need to use the Curves tool of your editing software. Where it is, and how to activate differs for each one, but the Curves tool is very common and should be easy to find.
Now, how to adjust the black and white point of an image will also vary depending on your software. But the idea is the same: Bring the left end of the histogram to the right, and the right side of the histogram to the left. With my software, this is done with the little triangles at the bottom of the Curves box. AFAIK, most Curves have a diagonal line overlaying the image’s histogram.
To adjust the black & white points, I need to move the left triangle to the right, and the right triangle to the left. This is how Capture NX2 is done. With GIMP, I would have to 'grab' the dots at the end of the diagonal line (move the bottom left of the line to the right, and the top right of the line to the left). So you'll need to read your software's instructions to find out what you need to do and how to move the points.
OK, so you’re probably thinking, “Yeah, but how far do I move them?” The answer is in the histogram! You want to move the points until you get into where the histogram says the pixel counts start to rise. I’ve marked those spots in the screenshot above with green. So I would just move the black point (the triangle on the left) and drag it until it’s under where I marked in green. I would repeat the process with the white point, moving it to the left until I get to the ‘end’ of the histogram.
The result is this:
I now have a nice, contrasty image that’s no longer ‘flat’ or ‘dull’, and I haven’t created any banding in the image (Take THAT, all you ‘get it right in the camera’ fanatics!)
-----------------------------------------------
So… that’s about it. Hopefully, you’ve learned how to incorporate histograms into both your field and post work, how they work, what they tell you, and how to adjust your exposure and Curves to get the shot you really had in mind!
If anyone has any suggestions or ideas on how to improve on this tutorial, just sing out!
Go forth and actuate!
Ken
Last edited: