Looking for tips on manipulating the histogram

Hello,

I have a series of images with such histogram:
Screenshot_20180304_182910

I can stretch the histogram to the right using Levels module in darktable:
Screenshot_20180304_183752

But I am wondering what would be the best way to shift the left part of the histogram to the right.
I can just drag the histogram to the right using the mouse which basically adjusts the black level in Exposure module but in that case the image losing black colors
Screenshot_20180304_184014

I was wondering what tools do you use to manipulate the histogram.
And also, do you always try to achieve the ideal histogram or that is not possible or a bad idea for some pictures?
Screenshot_20180304_184921
Any tips would be greatly appreciated.

In general, the interesting parts of the image should have a steeper slope in the histogram; the steeper the curve, the greater the contrast. E.g., in your dt example, stretching it won’t cause the shadow-midtone region to pop. Increasing the exposure by 1 EV would have a bigger impact than just levels by itself. You could also try to move the middle line in levels, which I think controls the gamma.

Visual example
(1) Tiger growl!

(2) Tiger ROAR! (equalized)

See how the second histogram has more peaks and therefore more slopes?

For examples on how a Gaussian distribution would look like versus a uniform one, see: Fred's ImageMagick Scripts: REDIST.

I generally use the Tone Curve and exposure modules to cover the bulk of pushing the histogram. Then slight enhancements with Luma in the Equizer module.

If the need is drastic, I’ll use tone mapping.

For my experience, curves are the thing for working the histogram. Most simple tone manipulations can be done with curves. For instance, 2x exposure compensation can be done by simply dragging the upper control point to the middle of the grid, as the straight line of the “curve” now represents multiplying each tone by 2. White balance can be done easily with per-channel curves, again with the upper control point for each channel.

Once you know the fundamental concept of the curve and do some playing with it, you can readily look at the image and figure out the control points you need without experimentation. As a corollary to the image I posted at Flowers in the Dining (not Living) Room, here’s the processed image before the curve:

What I wanted to do was darken the background. Fortunately, the foreground flower was lighter than the background, so the curve shown here did the trick:

The two end points were left alone, the first point I added was to drag the lower part of the histogram into darkness, and the other point lifted the flower back up a little.

This example is in my hack software, but any of the software discussed here that does curves will behave similarly.

Oh, back to the histogram, note that mine here is bunched up to the left. I did that deliberately with the blackwhitepoint tool. I put the left slider well into the data, in order to crush the shadows and emphasize the lighter flower. Didn’t go to far with that, because any of the histogram to the left of that point is now lost data. This tool is really just a curve with two points, the lower-left and upper-right points, and the sliders move them in order to set the curve at the limits of the data, as seen in the histogram. Here’s the processing before the blackwhitepoint:

Notice how flat the image looks, and regard the histogram: all the data is below about 136 on the 0-255 scale. If you go back up to the first screenshot, note the right slider of the blackwhitepoint is at about 136. That spreads the image data across the full data range. The left slider is set as I described above, well into the data.

What the histogram mainly tells me is where to set the black and white points, what is colloquially known as a “contrast stretch”. After that, I just look at the image and figure out if it needs lightening (more likely) or darkening, and apply a curve accordingly. And sometimes I get lucky, as with this image, in that the subject can be manipulated separately from the background just using a curve, and not having to resort to layer masks or other stuff.

Edit: I just went back and read what I wrote, and it might be a bit hard to navigate. In each screenshot, the upper-left pane shows the tools that have been applied, in order of application from top to bottom. The tool in play is highlighted, and its controls are in the lower-left pane. So, the above sequence of screenshots goes 2-3-1, where 2 is the blackwhitepoint tool, 3 is the curve, and 1 is the working color profile application right after opening the image. Sorry if this is confusing…

My first post was on how slope and peakedness (or kurtosis) of the histogram (or curve) would affect contrast. I totally forgot to link to this excellent tutorial:
– Understanding Digital Camera Histograms: Tones and Contrast
– Understanding Digital Camera Histograms: Luminosity and Color
– Just keep on reading the other tutorials there while you are at it!

I also hinted at possible tools. To be clear, try dt’s equivalent of the
– curve tool
– level tool
– contrast tool
– gamma tool
– exposure tool
– equalizer tool
– and others.

The important thing is to observe how each tool affects the histogram. Don’t forget to look at the preview image too :wink:, but as an exercise take a look at both and see what is happening.
– Which parts are relatively flat?
– Which are steep? The middle of a given slope has the sharpest contrast BTW.
– Is there clipping? When clipping happens, a bar or line appears at one or both ends.

In dt, the histogram is a tool in and of itself. Try hovering over it and you will see
image

You could do other awesome things there: change the exposure, black point, toggle color channels and switch between views (log histogram, linear histogram and waveform!).

It is not possible to have one histogram to rule them all.

If you take, for example, an image during a low standing sun with the sun behind you, you often get very pastelly images. Looking at the histogram will show you, that all the data will be in the middle, with no (or little) highlights and no (or little) shadows. With this kind of image you can stretch the histogram to get it covering the whole space but the result will normally not be what you saw when taking the image, wich was a midtoney, pastel like palette.

Oh and curves are the way to go. Simple rule of thumb: where the curve is flat you lessen contrast, where the curve is steep you increase contrast.

1 Like

Wow. Great example. I will try it for sure.

I have not had much luck with Tone Curve module yet. I just could not find a way to adjust it precisely in darktable. I will try it again or maybe I will try doing that in RawTherapee and see if it is any different

Watching PBS with my wife, decided to do a screenshot sequence showing what we’ve been discussing. I’m using my hack software, but the histogram and curve should work similarly in any other software.

First screenshot shows the image after initially opening the raw file. This is the raw data, linear gamma, with my calibrated camera profile assigned:

Firstoff, notice how dark is the image; that’s the linear range of the camera sensor. The histogram shows the linear data, bunched up at the bottom. Now, most software will automatically convert the image to a working profile; mine doesn’t so the first tool applied is a colorspace conversion:

Note the image tone doesn’t change, but the histogram does. This is because the colorspace conversion uses a working profile with a gamma of 1.8, which spreads the data out a bit. Oh, need to mention the displayed image is being converted to the calibrated display profile which has a gamma of about 2.2. Since the gamma conversions are being done through the profile conversions, the displayed data looks the same as before the conversion. @Elle will need to explain that; I’m still not there yet… :smiley:

So, what I typically do first is to “contrast-stretch” the image data to cover the full data range. This is simply “spreading” the histogram out to the data limits. I have a tool to do that, but I’m going to use a curve instead to show how that works:

If you look back at the histogram in the previous screenshot, note the lower bound of the data is about 5, and the upper bound is about 110, in the range 0-255. Come back to this screenshot, and note the “curve”, it’s a straight line between 5,0 and 110,255. That curve spreads the image data out to the bounds, rendering it as we’d prefer to see it. Some call it “setting the black and white point”.

Now, depending on your monitor, you should notice the image has a distinct blue cast. If you can’t see it in the image, it’s definitely notable in the histogram; the blue plot in the histogram is definitely shifted to the right of the red and green plots, on the upper part of the histogram. We can change that with a blue-channel curve, like this:

Note that the blue channel is selected, so the curve only works on the blue component of each pixel. This is also a “linear” curve, but this time the control point is dragged down the right hand side. That “pushes” the blue channel to the left; if we were to drag it left across the top, it would “pull” the channel to the right. This is essential white balance.

Now, the image looks a little light to me, so I’d normally put in another RGB curve and pull it down a bit:

Note the histogram bunches toward the left a bit. But the desired effect is to darken the image; at this point, I’m looking less at the histogram and more at the image itself.

Lastly, I’ll illustrate what @McCap described about contrast:

I just added a control point at the upper end of the curve, and drug it above the “neutral line”. Now, the middle part of the curve has a steeper slope, and that increases contrast. Now, I’ll drag the left point up and the right point down, flattening the curve:

The middle of the curve is now flatter, and the corresponding image has less contrast.

Hope this helps…

9 Likes

Fascinating post, but this part is most interesting. Is the blue shift specific to this image, or does it always happen after setting the black and white points through a tone curve?

I think it’s image-specific. The lighting conditions were dominated by the blue sky…

Oh, and my calibrated camera profile was built on an image shot under direct daylight conditions.

1 Like

Great post!
Thanks a ton. I will keep playing with curves in dt.

I have achieved the results I wanted using Tone Curve module.
The changes you make there have to be very little and very precise so it took me almost an hour to figure it out.

As a side note, I have noticed that Shadows and Highlights module slightly pushes the histogram to the middle from both ends. Can be useful sometimes as well.

Yes, emphatically, to “little”. In images with a lot of tonality, it doesn’t take much curving to show an appreciable difference.

One thing we haven’t discussed here is the specific mechanism of a curve, how it works. I found, once I understood that, I wasn’t looking at the histogram so much; instead, looking at the image and making relevant curve adjustments to suit. The histogram then became more a tool to find the data range of the image region I was messing with, and to see where I was starting to push data out-of-range at either end.

Well, that might have more to do with flunking the math course where we did those xy plots… :smile:

FWIW here is my basic method for processing based on a curve which I frequently use (and will be interested in comments).

  1. Look at the camera jpeg and see if there’s anything good you want to emulate when in the raw processing.
  2. Open Raw, set a quick & rough white balance to facilate…
  3. Adjust main Exposure to taste / clipping. (RT has this, assuming DT too?)
  4. Do proper white balance and tweak saturation / chromaticty to taste.
  5. Go to curve e.g. Lab L*or whatever you like, and so you can place points (e.g. RT “custom”)
  6. Adjust black and white points to taste / clipping.
  7. Put a point about half way along an adjust to taste.
  8. Mentally divide the lower half into 3 segments and put a point say 1/3rd up and adjust to taste.
  9. And again 2/3rds up.
  10. And 2 more above the mid-point, leaving the brightest part until last.
  11. Hopefully it now looks good…

RT allows fine-tuned movements by holding CTRL whilst you drag the point, maybe DT has something similar.

@Andrius
Yes, with the latest 2.4 release of darktable you can use CTRL for fine-tune and SHIFT for fast moves.

To achieve the effect you want you just need:

  1. Open the Tone Curve.
    2.Using the mouse, click on the point at the left edge of the curve and drag it straight to the top, until you get the space in the blacks that you want.
  2. Keeping dragging the point, now move it to the right until you get the desired histogram curve.
  3. Enjoy…
1 Like

Thanks for the tip, it works as a charm! Tone Curve is my “go to” module now :sunglasses:

Be ware that the Tone Curve adjusts the histogram but affects the image contrast so you may need to use the Local Contrast to recover the detail, This may explain your previous comment regarding the tool.
At least, Levels and Global tonemap suffer the same issue, I think this is because the gamma correction is outdated.

I do not know why you want to modify the histogram, but if you are looking to improve the shadows in your image, I may suggest better to use the Histogram this way:
a) To adjust the blacks, right click the mouse on the histogram’s left zone and drag it to the right until you get the desired look.
b) To adjust the whites and the shadows, left click on the histogram’s right zone and drag it to the left or the right until you get the desired look.

This way the histogram will not have a lovely curve but your image will look brilliant and you will not need to fix the contrast any more (neither the exposition).
I guess the Histogram has a better performance than the other tone tools because it was made in a different period of time and they do not share the same algorithm.