An image histogram is a distribution of intensity values, not a map of where those values occur. It is useful for inspecting contrast and for constructing global intensity transformations, but the discarded spatial positions matter: two visibly different images may have exactly the same histogram.
Counts, probabilities, and the cumulative distribution
Definition 8.1.1
(Histogram, cumulative distribution and the floor map)
Suppose a grayscale image has N>0 pixels, with integer levels 0,...,L-1. Let h(r) be the number of pixels at level r, and put p(r)=h(r)/N. Thus sum_r h(r)=N and sum_r p(r)=1. The cumulative distribution is
The global equalization-style map is
The output histogram of the mapped image is h_out(s), the number of pixels whose new level is s.
We use this exact convention throughout: floor rounding, all levels included, and no subtraction of the first positive cumulative value. Software and lecture notes may use different rounding or a minimum-CDF adjustment; those choices can produce different numerical results. Because the image is finite and levels are discrete, the output histogram need not be uniform.
Proposition 8.1.2
(Basic properties of the floor map)
Under the convention above:
Fis nondecreasing andF(L-1)=1;Tis nondecreasing, takes values in{0,...,L-1}, andT(L-1)=L-1;- the output counts are
h_out(s)=sum_{r:T(r)=s} h(r), andsum_s h_out(s)=N.
Proof
(Monotonicity and merged counts)
Each is at least , so , and . Multiplying by keeps the order, and the floor function is nondecreasing, so gives . Since , we have , hence . At the top level, .
For the third item, every pixel has exactly one input level and is sent to the single output level . The pixels with output level are therefore exactly those whose input level lies in , and these input classes are disjoint for different . Adding their counts gives ; adding over all counts every pixel once, giving .
A darker input level therefore cannot map above a lighter input level, and equal input levels always receive the same output level.
Worked examples: calculate the output, not just the map
Worked example 8.1.3
(A map that happens to be the identity)
Take a 2 x 4 image with levels 0,1,2,3:
0 0 1 2
1 2 2 3
The counts are [2,2,3,1] and N=8. With L=4, calculate:
Input level r | h(r) | F(r) | floor(3 F(r)) |
|---|---|---|---|
| 0 | 2 | 2/8 | 0 |
| 1 | 2 | 4/8 | 1 |
| 2 | 3 | 7/8 | 2 |
| 3 | 1 | 8/8 | 3 |
Here the mapping happens to be the identity, so the output counts are again [2,2,3,1]; equalization is not guaranteed to visibly change every image.
Worked example 8.1.4
(Counts that merge: the histogram [4,0,4,0])
To see a nontrivial transformation, consider counts [4,0,4,0], again with eight pixels and four levels. The cumulative probabilities are [1/2,1/2,1,1], so 3F=[1.5,1.5,3,3] and the map is [1,1,3,3]. By the merged-count formula, h_out(1)=h(0)+h(1)=4, h_out(3)=h(2)+h(3)=4, and h_out(0)=h_out(2)=0 (no level maps there). The output counts are [0,4,0,4]: all level-0 pixels become 1 and all level-2 pixels become 3. There were no input pixels at 1 or 3, even though the map is defined for those levels, and the total is still 4+4=8.
Worked example 8.1.5
(An edge case: a collision loses information)
A four-level image has counts [1,1,1,5]. Find the map under the stated floor convention and its output counts. What information is irretrievably lost if only the mapped image is kept?
The cumulative probabilities are [1/8,2/8,3/8,1]. Multiplying by 3 and taking floors gives T=[0,0,1,3]. Input levels 0 and 1 both map to 0, level 2 maps to 1, and level 3 stays at 3; hence the output counts are [2,1,0,5]. At any output pixel equal to 0, the mapped image alone cannot say whether its input was 0 or 1. This is a specific loss due to a many-to-one intensity map, in addition to the position information lost when only a histogram is retained.
A many-to-one map merges counts. It does not divide a populated input bin across several outputs, so a discrete image cannot always be made exactly uniform by a deterministic mapping that treats equal intensities identically.
Counterexample mode
Equalization does not give a flat histogram
Claim: after this map the output histogram is uniform, with N/L pixels at every level. Take counts [4,0,4,0] with N=8, L=4; a flat result would be [2,2,2,2]. We computed the output [0,4,0,4], which is not flat. Worse, no pointwise map can reach [2,2,2,2] here: the four level-0 pixels all receive the same output level, which would then hold at least 4 pixels, more than 2. What is true is only the proposition above: the map is monotone, preserves the pixel total, and merges whole input bins.
Common mistake
(Reading the map as the output histogram)
The list T=[1,1,3,3] is where each input level goes; it is not the output count list. Computing h(T(s)) for s=0,1,2,3 gives h(1),h(1),h(3),h(3)=0,0,0,0, which does not even sum to 8. The correct counts are h_out(s)=sum_{r:T(r)=s} h(r), namely [0,4,0,4].
Common mistake
(Multiplying by L instead of L-1)
With L=4 levels and F(L-1)=1, using floor(4F(r)) sends the brightest level to 4, which is not a valid level. The factor is L-1, so that the largest cumulative value 1 maps to the top level L-1.
Quick check
(An 8-pixel image with L=4 has counts [3,1,0,4]. Find T and the output counts.)
Compute the cumulative counts first.
Solution · Answer
The cumulative probabilities are [3/8,4/8,4/8,1], so 3F=[9/8,12/8,12/8,3] and T=[1,1,1,3]. Levels 0, 1 and 2 all map to 1, so h_out(1)=3+1+0=4, and h_out(3)=4. The output counts are [0,4,0,4].
Quick check
(A 6-pixel image with L=4 has every pixel at level 2. What are T and the mapped image?)
Write the counts [0,0,6,0].
Solution · Answer
F=[0,0,1,1], so T=[0,0,3,3]. Every pixel has level 2 and is sent to 3, so the mapped image is constant at level 3. The map does not spread a single populated bin.
Quick check
(Two images have the same histogram but different pixel arrangements. Must their mapped images have the same histogram?)
Ask what T and h_out depend on.
Solution · Answer
Yes. T is computed from h alone, and h_out(s)=sum_{r:T(r)=s} h(r) is computed from h and T. The mapped images may still differ in arrangement.
What the histogram cannot identify
The two arrays below both contain two zeroes and two threes:
0 0 0 3
3 3 3 0
Their histograms are identical, but their positions and boundaries differ. Applying the same pointwise map to each array retains that difference in arrangement unless the relevant levels collapse to one. A histogram therefore cannot recover edges, shapes, or pixel locations on its own. A global transformation uses the same map everywhere; it may improve the distribution of contrast for some images but does not guarantee improvement in every region or preserve all detail.
For a color image, specify the representation before using such a calculation: independently mapping three RGB channels is a different operation from transforming one luminance channel and may change color balance. Counts in this section assume one grayscale channel and no interpolation between levels.