Demystifying Histograms

480sparky

Chief Free Electron Relocator
Supporting Member
Joined
Mar 8, 2011
Messages
25,160
Reaction score
9,010
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:

2.jpg



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:

01.jpg



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.

03.jpg



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’.

04.jpg



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?

05a.jpg



So let’s see if the histogram bears this out.

05.jpg



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.

06.jpg



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.

07.jpg



To show you how the histogram represents the pixel count of the image, I’ll add some arrows.

07a.jpg



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:

07b.jpg



While an RGB histogram is ‘built three times’, once counting the red pixels, once counting the green, and the third counting the blue pixels.

07.jpg



So take an ordinary image taken with your camera, and the histogram will look like this:

08.jpg



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:

09.jpg



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:

10.jpg



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.

11.jpg



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!

12.jpg


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:

14.jpg



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:

13.jpg



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:

15.jpg



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.

16.jpg



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.

17.jpg



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:

18.jpg



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:
Thank you! Thank you!

I'd picked up many bits and pieces of this information enough to be dangerous, but never seen it all together and so well laid out. Especially using curves to prevent banding badness.

:mrgreen:
 
I'm headed out the door for the evening, so I only skimmed this, but I'll definitely be coming back to really read it later--this looks like excellent information, sparky!! And even though I do usually refer to my histogram (except on this trip I took with my mother--and the results show it!), I have never really understood more than the very basics of it (I mean, the VERY basics--if the whole histogram is too far to the left, it's gonna be underexposed, and if it's all too far to the right, it's gonna be overexposed). I've NEVER really been sure when to use levels or curves or something else when processing a photo, I just mess with things until it seems like it looks better, on the monitor. Never realized what the "banding" that sometimes results on the histogram was, or how it affected the photo itself.

Back some time ago, someone started a thread where they posted a picture and several histogram choices, and then you could guess which one was the histogram that actually went with the picture. I thought it was a fun and educational exercise but it didn't last very long.
 
In the last part...can this be done in levels, as well, or must it be done in curves?

Sent from my iPad using Forum Runner
 
Nice! I vote STICKY on this one!
 
In the last part...can this be done in levels, as well, or must it be done in curves?

Sent from my iPad using Forum Runner

It can be done in levels but curves is a more powerful too that is good to master for the long haul.

I think this was a very nice explanation.
Now you can add an addendum about Expose to the Right (ETTR) and why a histogram with a big pile on the right may not mean the highlights are completely blown.
 
In the last part...can this be done in levels, as well, or must it be done in curves?

Sent from my iPad using Forum Runner

It can be done in levels but curves is a more powerful too that is good to master for the long haul.

I think this was a very nice explanation.
Now you can add an addendum about Expose to the Right (ETTR) and why a histogram with a big pile on the right may not mean the highlights are completely blown.

I originally considered having ETTR as Part Six, but thought otherwise once I got done with Parts 1-5. ETTR, and using the camera's "Blinkie" function, can be yet another subject.
 
.........Back some time ago, someone started a thread where they posted a picture and several histogram choices, and then you could guess which one was the histogram that actually went with the picture. I thought it was a fun and educational exercise but it didn't last very long.

That was some goofball from Iowa. Suffers terribly from NAS. I think he got shocked one time too many and fried his brain.
 
I just wanted to mention that the contrast adjustment is (or can be) mathematically equivalent to using curves the way you did, but your photo editor may be filling in values differently with the curves adjustment. This is an implementation issue, in my mind.

Also, using a higher bit depth like 16 bit can prevent noticeable banding in any case.
 
Good job Sparky.

Joe
 
If you edit in PS you should investigate levels instead of curves because you will be adjusting the histogram and see the results and get better adjustments.
 
Thank you sparkles.
 
Excellent post, thank you for taking the time to do it Sparky.
 

Most reactions

New Topics

Back
Top