# Demystifying Histograms



## 480sparky (Dec 30, 2012)

Demystifying Histograms

Even though I&#8217;ve only been on the forum for less than two years, I&#8217;ve noticed that there has been very little discussion about one of the most useful tools for the digital photographer.  And that&#8217;s a subject of histograms.

So to rectify that situation, I&#8217;m going to create a tutorial that will hopefully explain what a histogram is and how to properly use it.

I&#8217;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&#8230; 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 &#8216;bright&#8217; 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 &#8216;middle gray&#8217; (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&#8217;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&#8217;s see what a blend of grays look like.  I spread the shades of gray between 64 and 192 horizontally across the &#8216;image&#8217;.







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&#8217;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 &#8216;built&#8217;.  The orientation of the image (portrait or landscape) is not relevant, nor is the aspect ratio of the image.

Now I&#8217;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&#8217;ve dealt only with shades of gray.  How dull our world would be without color.  So let&#8217;s add some color!

Let&#8217;s take the gray image, and divide into three sections.  I&#8217;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&#8217;ll add some arrows.







Don&#8217;t worry about the colors in the histogram not matching the colors in the image.  They&#8217;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 &#8216;built&#8217;, using the brightness of the individual pixels, to create a bar chart.


-----------------------------------------------
3. Different Types of Histograms

There&#8217;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 &#8216;built three times&#8217;, 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 &#8216;seen&#8217; 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&#8217;ve &#8216;nailed&#8217; 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 &#8216;looks like&#8217;.

For instance, let&#8217;s say you&#8217;re out shooting a snowy scene on a sunny day.  Your eye&#8217;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&#8217;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 &#8216;piled up&#8217; along the right side of the histogram.  And there&#8217;s very few, if any at all, on the left.  So you end up with a bunch of snow that&#8217;s totally &#8216;blown out&#8217;, meaning it is pure white and contains no detail.

But suppose you get into the habit of looking at the image&#8217;s histogram on the camera&#8217;s monitor when you&#8217;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&#8217;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&#8217;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 &#8216;low-key&#8217; 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 &#8216;missed the shot&#8217; 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&#8217;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: &#8220;But wait! There&#8217;s more!&#8221;?  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&#8217;re happy with the exposure, but it just doesn&#8217;t look right.  You may say it &#8216;looks flat&#8217;, or &#8216;it&#8217;s dull&#8217;, or &#8216;it just isn&#8217;t crisp&#8217;.  You want it &#8216;to pop!&#8217;  The issue may be your camera&#8217;s dynamic range is far greater than the dynamic range of the scene you captured.

Here&#8217;s an example:







Kinda dull, isn&#8217;t it? Why? Because there&#8217;s no real dark and light areas.  It lacks contrast.  We _expect_ to see blacks and whites.  So let&#8217;s look at the histogram of the image:







Yep.  Just as you thought!  There&#8217;s no real dark and light areas in the image.  So now it&#8217;s time to learn how to &#8216;set&#8217; the white and black points on the image.

The idea here is to get the histogram to &#8216;stretch out&#8217; 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 &#8216;comb&#8217; it. Sections of the histogram aren&#8217;t filled because of the process.  You end up with a histogram with lines in it:







This means you&#8217;ll end up with artifacts called &#8216;banding&#8217; 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&#8217;t try to fit the histogram to the graph&#8230;.. 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&#8217;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&#8217;re probably thinking, &#8220;Yeah, but how far do I move them?&#8221;  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&#8217;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&#8217;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 &#8216;end&#8217; of the histogram.

The result is this:







I now have a nice, contrasty image that&#8217;s no longer &#8216;flat&#8217; or &#8216;dull&#8217;, and I haven&#8217;t created any banding in the image (Take THAT, all you &#8216;get it right in the camera&#8217; fanatics!)


-----------------------------------------------

So&#8230; that&#8217;s about it.  Hopefully, you&#8217;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


----------



## keith foster (Dec 30, 2012)

Thanks for taking the time to do this.  Good info for anyone wanting to improve their photography.


----------



## squirrels (Dec 30, 2012)

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:


----------



## sm4him (Dec 30, 2012)

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.


----------



## fotograph (Dec 30, 2012)

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


----------



## cgipson1 (Dec 30, 2012)

Nice! I vote STICKY on this one!


----------



## The_Traveler (Dec 30, 2012)

fotograph said:


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


----------



## 480sparky (Dec 30, 2012)

The_Traveler said:


> fotograph said:
> 
> 
> > In the last part...can this be done in levels, as well, or must it be done in curves?
> ...



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.


----------



## Overread (Dec 30, 2012)

Added it to the http://www.thephotoforum.com/forum/...9286-new-feature-photography-tutorials-3.html thread


----------



## 480sparky (Dec 30, 2012)

sm4him said:


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


----------



## christop (Dec 30, 2012)

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.


----------



## Ysarex (Dec 30, 2012)

Good job Sparky.

Joe


----------



## Mully (Dec 30, 2012)

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.


----------



## kathyt (Dec 30, 2012)

Thank you sparkles.


----------



## BlackSheep (Dec 30, 2012)

Excellent post, thank you for taking the time to do it Sparky.


----------



## 480sparky (Dec 30, 2012)

BlackSheep said:


> Excellent post, thank you for taking the time to do it Sparky.



I was bored to tears last week when the big snowstorm rolled in.  Just polished it off this morning.


----------



## BlackSheep (Dec 30, 2012)

Your boredom was well directed. 
Not just for total newbie photographers, but also for us former film shooters who are still struggling with the whole histogram concept. Much appreciated!


----------



## nmoody (Dec 30, 2012)

Bookmarked this for later, it looks very detailed and easy to understand. 

Thanks for taking the time to break this down and explain it.


----------



## weepete (Dec 30, 2012)

Well done Sparky, very well explained thank you, it is much appreciated mate!


----------



## Farmclicker (Dec 31, 2012)

I appreciate it as well. Thank you very much for all the time that went into that. I know a lot more now (Which is not hard because I know very little).


----------



## Buckster (Dec 31, 2012)

Well explained Sparky.  That will be a really huge help to those who are unfamiliar with histograms.  Good job!


----------



## ratssass (Dec 31, 2012)

...another door opened for me,and now it has also spilled over into PP.Thanks Sparky!!


----------



## jwbryson1 (Dec 31, 2012)

Great job as always Sparkomatic.

I do have remaining questions that I will continue to explore on my own, but I'd love to hear more about them here if anybody is up to the task:

1.  In LR3 and LR4, I'm not sure that there is a function where you can "slide the triangles" to get the contrast adjusted without banding.  Does anybody know if this exists and where to find it in LR3 or LR4?

2.  Do all three colors in the RGB histogram have to stretch out across the spectrum from left to right to be a "correct" exposure?

3.  Does it make a difference in terms of a "correct exposure" which colors in the histogram appear the highest on the histogram?  (I think this may be a "duh!" question and the answer involves what colors appear in the image, but I'm throwing it out there just to see if it sticks).

Thanks!


----------



## 480sparky (Dec 31, 2012)

jwbryson1 said:


> ...........1.  In LR3 and LR4, I'm not sure that there is a function where you can "slide the triangles" to get the contrast adjusted without banding.  Does anybody know if this exists and where to find it in LR3 or LR4?



I'm not a LR user, but I'd say you have a lot more latitude when adjusting the white & black points ("slide the triangles") when you are working with a raw file as opposed to a JPEG.



jwbryson1 said:


> 2.  Do all three colors in the RGB histogram have to stretch out across the spectrum from left to right to be a "correct" exposure?



Not necessarily. If you take a photo of a yellow flower, the blue portion of the histo may show an 'incorrect' exposure, but since there's not much blue in the image to begin with, you can ignore it.



jwbryson1 said:


> 3.  Does it make a difference in terms of a "correct exposure" which colors in the histogram appear the highest on the histogram?  (I think this may be a "duh!" question and the answer involves what colors appear in the image, but I'm throwing it out there just to see if it sticks).



The 'height' of the histogram is really not relevant unless it's at one end or the other. That would indicate an over- or under-exposure.


----------



## Mully (Dec 31, 2012)

In LR the histogram is displayed in RGB in PS levels the histogram is a combination of all colors and effects the overall light and dark of the image.  Exposure is "most often" correct when the histogram is close L to R ...in a dark or light scene this will change with most of the info L for dark or R for light images.  I use PS to change levels and not in LR


----------



## CherylL (Dec 31, 2012)

Thanks for taking the time to post this tutorial.


----------



## ronlane (Dec 31, 2012)

Way to go Sparky. Thanks for putting this together. I read and understand what you are showing us. Now I just need to get home and play with it on the camera and in post.


----------



## jwbryson1 (Dec 31, 2012)

Mully said:


> In LR the histogram is displayed in RGB in PS levels the histogram is a combination of all colors and effects the overall light and dark of the image.




????   :scratch:


----------



## Rick58 (Dec 31, 2012)

Hey Sparky...THANK YOU!

Before even reading this I want to thank you. I'm dumber then a sack of hammers when it comes to histograms. Time to pour a cup of coffee and read through this when I get home. Looks very interesting and thanks for the effort :hail:


----------

