Mean value of normalized pixel intensity histogram

Viewed 351

I'm following a paper (It's accessible here) that characterizes images based on certain attributes. These attributes are all derived from histograms, one being the pixel intensity histogram. The images are greyscale.

Now, it states that all histograms are normalized, I quote: "All histograms are normalized (i.e. the sum of all histogram bins equals 1)." There is also an example histogram which looks as follows:

enter image description here

From this, I can see the image contains a lot of white pixels (intensity 255 (256?))

Now it goes on to compute the mean, standard deviation and more. This is where I get stuck, I quote: "Mean Value: ... It is computed as \frac{\sum_i h_i}{256} where h_i is the value of the i-th histogram bin (i \in [0..255])"

Something got me confused here, because the way I see it, that value will now always be the same? Since the sum over all bins is 1 because it is normalized. What am I missing here? In their table a bit down they found a mean of in the 180s, which seems to suggest the mean is just the mean of all pixels (since it's greyscale that translates 1 to 1 to intensity, but then I'm still stuck for the other formulas.

1 Answers

You may not reading the formula correctly.

It supposed to be: mu = sum(i*h[i])/256 were i goes from 0 to 255.

Note:

  • A more accurate formula is: mu = sum(i*h[i])/255

Here is a MATLAB code sample that demonstrates the computation:

I = imread('cameraman.tif'); % Read input image (Grayscale image).
I = im2double(I); % Normalize pixels to range [0, 1] (instead of [0, 255])
H = imhist(I, 256)'; % Collect histogram - 256 bins (row vector).

n_pix = numel(I); % Total number of pixels.

% Normalize histogram - divide each bin by number of pixels.
H = H / n_pix; % sum(H) equals 1

i = 0:255; % i goes from 0 to 255

mu = sum(i.*H)/255; % 0.4656

meanI = mean2(I);

display(meanI)
display(mu)

Result:

meanI =

    0.4656


mu =

    0.4656

Why is it correct?

Assume gray level range is [0, 255] (not [0, 1]):

  • H[i]*n_pix is the number of pixels with value i in the image.
  • i*H[i]*n_pix is the sum of of gray levels contributed by gray level i.
    All pixels with i=0, contributes 0 to the total gray levels sum.
    All pixels with i=1, contributes 1*H[1]*n_pix to the total gray levels sum.
    ...
    All pixels with i=255, contributes 255*H[255]*n_pix to the total gray levels sum.
    Note: we multiply by n_pix because H elements are divided by n_pix (normalized).
  • The sum of i*H[i]*n_pix is the sum of all the gray levels in the image.
  • The sum of i*H[i]*n_pix/n_pix = sum(i*H[i]) is the mean of the gray levels.

Because gray level range is [0, 1], we have to divide the result by 255.


It may be better understood if you turn the image into a vector sort the pixels in ascending order.
I suggest you to take a small sample (like 20 pixels), sort the pixels, and follow the computations.

Related