1
$\begingroup$

I am trying to figure out how to display a histogram of a digital image in the face of massive outliers (lots of shadows, highlights, or lots of anything inbetween). If I simply choose the bin with the most entries to be the '100% height' of my fixed display area the rest of the bins are dwarfed and you can't really get any useful information by looking at it.

I attempted to find the standard deviation between the bins then only include bins within a certain number of std devs from the average when picking the '100% height' bin, but it didn't turn out too well in the general case... certain number of std devs worked well for some images and not others.

A good example of what I want is Photoshop's histogram, but I'm not sure how they accomplish this and I've come up short on the google. Does anyone have any advice?

  • 1
    Have you already tried a simple logarithmic axis scaling?2011-06-23

2 Answers 2

2

You could reject the tallest 5% (for example) of the bins, and choose the height within which the remaining 95% fit. That is, sort the heights of the $n$ bins and use the height of the $0.05n$-th tallest bin. I don't know how Photoshop does it, but this is how I would do it if I were writing Photoshop.

Logarithmic scaling of the heights is also a nice solution, but it changes the shape of the histogram. Therefore, most image editors give you a choice between linear and logarithmic scaling, so one still needs a solution for when the user chooses linear scaling.

  • 0
    Thanks! That's probably what I'll end up doing however it still leaves some cases that don't work out too well, would there be a good way to 'select' the percentage to reject thats adaptive to any input image? I'm thinking the variance of the bins may work. i.e. a histogram which a high variance will result in a lower percentage being excluded from picking the max2011-06-23
3

Regarding Photoshop: their histogram depicts the frequencies of luminance in the image. The left most side is black, the right most side is white. The spectrum in between these extremes is referred to as the tonal range.

If you want to produce something similar to what Photoshop does, then for each pixel in the image, take that pixel's RGB value and map it to the corresponding relative luminance. From Wikipedia, you can do this by:

$Y = 0.2126 R + 0.7152 G + 0.0722 B$

This will get you a set of values between zero and 255. From there, you can construct your histogram.

  • 0
    Good info. The crux of the problem though is when (for example) there's a large amount of shadow and the left most bin is huge, when I display the histogram in a fixed height window there's a tall skinny beam on the left and the rest of the histogram is about 10-15 pixels high, which visually doesn't give you much information about the photo.2011-06-23