Every slide you need, in plain words, with every histogram and curve drawn, and the past-paper questions solved the way you write them in the answer script.
Slide 3. Image A looks foggy and gray; image B looks sharp and punchy. They show the same pollen. The difference is in how the gray levels are used, and the histogram shows that difference at a glance.
Slide 4. Definition. An image histogram is a graphical representation of the distribution of pixel intensity values in a digital image.
Applications: image enhancement, compression, segmentation. Very popular tool for real-time image processing.
Slide 5. The histogram function. For gray levels in [0, L−1], the histogram is the discrete function
where rk is the k-th gray level and nk is the number of pixels with gray level rk.
Given: 3-bit image, so L = 23 = 8 levels (0–7). One bin per level: h(0) … h(7).
| 5 | 5 | 3 | 3 |
| 4 | 3 | 3 | 3 |
| 0 | 6 | 7 | 2 |
| 1 | 7 | 2 | 2 |
Count each value: 0 appears once, 1 once, 2 three times, 3 five times, 4 once, 5 twice, 6 once, 7 twice.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| h(rk) | 1 | 1 | 3 | 5 | 1 | 2 | 1 | 2 |
Sum of all bars = 16 = number of pixels. The slide writes this as Σ h(x) = area of the image.
Try it, step by step: count each gray level of the slide 7 image and watch its bar grow.
sample.bmp is a 4×4 image with 6-bit gray values. Calculate its histogram and sketch it.
| 20 | 21 | 15 | 60 |
| 60 | 15 | 60 | 15 |
| 15 | 60 | 21 | 15 |
| 15 | 20 | 15 | 20 |
n = 16 pixels. Only four values occur:
| rk | 15 | 20 | 21 | 60 | all other levels |
|---|---|---|---|---|---|
| h(rk) | 7 | 3 | 2 | 4 | 0 |
Try it, step by step: the 6-bit sample.bmp: only 4 levels occur, all other bins stay 0.
Slide 9. What a histogram says. In the example h(2) = 10: ten pixels have intensity 2. A histogram gives only statistical information. It gives no indication of the location of the pixels.
Slides 10–13. Can two images have the same histogram? Can you rebuild an image from its histogram?
Slide 14. Colour image histogram, two types: (1) intensity histogram: convert the colour image to gray scale and show that histogram; (2) individual colour channel histograms: 3 histograms, one each for R, G, B.
Slide 16. Why the histogram is important. Its shape gives key information on the overall quality of the image and the possibility for enhancement. Looking at it is a fast way to judge quality. Processing the histogram improves an image quickly and automatically.
Slide 17. Uses of the histogram:
| 9 | 8 | 9 | 8 |
| 2 | 7 | 4 | 7 |
| 6 | 4 | 6 | 1 |
| 4 | 0 | 7 | 4 |
| bin | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| h(rk) | 1 | 1 | 1 | 0 | 4 | 0 | 2 | 3 | 2 | 2 |
| p(rk) | 1/16 | 1/16 | 1/16 | 0 | 4/16 | 0 | 2/16 | 3/16 | 2/16 | 2/16 |
Try it, step by step: count, then divide each count by N = 16.
sample.bmp is a 4×4 image with 8-bit gray values. Calculate its normalized histogram (PDF).
| 20 | 210 | 150 | 60 |
| 60 | 150 | 60 | 150 |
| 150 | 60 | 210 | 150 |
| 150 | 20 | 150 | 20 |
n = 16. Counts: 20 → 3, 60 → 4, 150 → 7, 210 → 2; all other levels 0.
| rk | nk | p(rk) = nk/16 |
|---|---|---|
| 20 | 3 | 3/16 = 0.1875 |
| 60 | 4 | 4/16 = 0.2500 |
| 150 | 7 | 7/16 = 0.4375 |
| 210 | 2 | 2/16 = 0.1250 |
| sum | 16 | 1.0000 |
Slide 21. Histogram processing is an enhancement technique: a transformation T is applied to the input f(x, y) to give the output g(x, y) = T(f(x, y)). T can be (i) histogram sliding, (ii) histogram stretching, (iii) histogram equalization.
Slide 22. Sliding: the whole histogram is simply shifted right or left, so you see a clear change in the brightness of the image. Shift right = brighter, shift left = darker.
Slides 23–24. Stretching increases the contrast (contrast = max − min pixel value). The histogram is pulled out to fill the whole range:
Three steps hidden in the formula: (1) slide the histogram down to 0 (f − MIN); (2) normalize it to [0, 1] (÷ (MAX − MIN)); (3) rescale to [0, 255] (× 255).
Levels used: 2 to 4. g = 7(f − 2)/(4 − 2): 2 → 0, 3 → 3.5 → 4, 4 → 7.
Slides 25–26. Examples: a gray, low-contrast face becomes clearer. Stretching works better if extreme intensities are clipped first (city photo).
Slide 27. Limitation of stretching:
Slide 28. Equalization stretches the histogram to fill the dynamic range and at the same time tries to keep the histogram uniform. Linear stretching only stretches; the bars keep their heights.
Slides 29–30. Case A (satellite image): after equalization the result looks high-contrast with a large variety of gray tones, but the histogram is not perfectly flat.
Slide 31. Histogram equalization is used to enhance contrast. Usually it can't perfectly equalize a digital image's histogram. That's only possible with continuous intensity values; real intensity values are discrete, so perfectly flat histograms are rare in practice.
Slide 32. It redistributes pixel intensities so they span the full range more evenly. Original: intensities clustered in a narrow range (too dark, too bright or low contrast). After: spread out, details more visible, contrast improved. It tends to enhance contrast and can be performed automatically.
Input: a discrete image f with L intensity levels.
Why the CDF? It counts the fraction of pixels darker than or equal to r. If 35% of pixels are at or below r, r goes to 35% of the way up the gray scale. Crowded levels make the CDF jump, which pushes neighbouring levels apart.
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 20.
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 1 | 6 | 3 | 2 | 3 | 2 | 1 | 2 |
Check: Σ nk = 1 + 6 + 3 + 2 + 3 + 2 + 1 + 2 = 20.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 1 | 0.0500 | 0.0500 | 7 × 0.0500 = 0.3500 | 0 |
| 1 | 6 | 0.3000 | 0.3500 | 7 × 0.3500 = 2.4500 | 2 |
| 2 | 3 | 0.1500 | 0.5000 | 7 × 0.5000 = 3.5000 | 4 |
| 3 | 2 | 0.1000 | 0.6000 | 7 × 0.6000 = 4.2000 | 4 |
| 4 | 3 | 0.1500 | 0.7500 | 7 × 0.7500 = 5.2500 | 5 |
| 5 | 2 | 0.1000 | 0.8500 | 7 × 0.8500 = 5.9500 | 6 |
| 6 | 1 | 0.0500 | 0.9000 | 7 × 0.9000 = 6.3000 | 6 |
| 7 | 2 | 0.1000 | 1.0000 | 7 × 1.0000 = 7.0000 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 2 | 6 |
| 2 | 4 | 3 |
| 3 | 4 | 2 |
| 4 | 5 | 3 |
| 5 | 6 | 2 |
| 6 | 6 | 1 |
| 7 | 7 | 2 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 0 | 1 | 1 |
| 2 | 6 | 6 |
| 4 | 3 + 2 = 5 | 5 |
| 5 | 3 | 3 |
| 6 | 2 + 1 = 3 | 3 |
| 7 | 2 | 2 |
Try it, step by step: the whole slide 36–40 example: count, the 5 table steps per level, the equalized histogram, then the output image pixel by pixel.
Slides 41–45. The four basic image types (dark, bright, low-contrast, high-contrast) all look similar after equalization, with histograms spread over the full range. Each one gets its own transformation curve (Figure 3.21).
Every equalization question has the same skeleton: histogram → PDF → CDF → (L−1)·CDF → round → mapping table → equalized histogram → staircase curve → output image. Learn it once; the solutions below repeat it with different numbers.
For the 5×5, 3-bit input image, find a transformation function that will approximately equalize its histogram. (i) Illustrate in detail (ii) give the equalized output image (iii) sketch the transformation curve (iv) draw the input and output histograms.
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 25.
| 0 | 0 | 1 | 1 | 2 |
| 0 | 1 | 1 | 2 | 4 |
| 1 | 1 | 2 | 4 | 5 |
| 1 | 3 | 4 | 5 | 6 |
| 3 | 3 | 5 | 6 | 7 |
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 3 | 7 | 3 | 3 | 3 | 3 | 2 | 1 |
Check: Σ nk = 3 + 7 + 3 + 3 + 3 + 3 + 2 + 1 = 25.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 3 | 0.1200 | 0.1200 | 7 × 0.1200 = 0.8400 | 1 |
| 1 | 7 | 0.2800 | 0.4000 | 7 × 0.4000 = 2.8000 | 3 |
| 2 | 3 | 0.1200 | 0.5200 | 7 × 0.5200 = 3.6400 | 4 |
| 3 | 3 | 0.1200 | 0.6400 | 7 × 0.6400 = 4.4800 | 4 |
| 4 | 3 | 0.1200 | 0.7600 | 7 × 0.7600 = 5.3200 | 5 |
| 5 | 3 | 0.1200 | 0.8800 | 7 × 0.8800 = 6.1600 | 6 |
| 6 | 2 | 0.0800 | 0.9600 | 7 × 0.9600 = 6.7200 | 7 |
| 7 | 1 | 0.0400 | 1.0000 | 7 × 1.0000 = 7.0000 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 1 | 3 |
| 1 | 3 | 7 |
| 2 | 4 | 3 |
| 3 | 4 | 3 |
| 4 | 5 | 3 |
| 5 | 6 | 3 |
| 6 | 7 | 2 |
| 7 | 7 | 1 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 1 | 3 | 3 |
| 3 | 7 | 7 |
| 4 | 3 + 3 = 6 | 6 |
| 5 | 3 | 3 |
| 6 | 3 | 3 |
| 7 | 2 + 1 = 3 | 3 |
Equalized output image: replace every pixel r by its s.
| 0 | 0 | 1 | 1 | 2 |
| 0 | 1 | 1 | 2 | 4 |
| 1 | 1 | 2 | 4 | 5 |
| 1 | 3 | 4 | 5 | 6 |
| 3 | 3 | 5 | 6 | 7 |
| 1 | 1 | 3 | 3 | 4 |
| 1 | 3 | 3 | 4 | 5 |
| 3 | 3 | 4 | 5 | 6 |
| 3 | 4 | 5 | 6 | 7 |
| 4 | 4 | 6 | 7 | 7 |
Try it, step by step: SP25 / SP24, every step.
A 4×5, 3-bit image [1,2,4,7,0; 2,1,3,1,5; 5,2,1,4,1; 7,6,3,1,4]. (i) Draw the histogram (ii) sketch the normalized histogram (iii) compute and sketch the equalized histogram (iv) sketch the transformation function curve (v) show the equalized output image.
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 20.
| 1 | 2 | 4 | 7 | 0 |
| 2 | 1 | 3 | 1 | 5 |
| 5 | 2 | 1 | 4 | 1 |
| 7 | 6 | 3 | 1 | 4 |
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 1 | 6 | 3 | 2 | 3 | 2 | 1 | 2 |
Check: Σ nk = 1 + 6 + 3 + 2 + 3 + 2 + 1 + 2 = 20.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 1 | 0.0500 | 0.0500 | 7 × 0.0500 = 0.3500 | 0 |
| 1 | 6 | 0.3000 | 0.3500 | 7 × 0.3500 = 2.4500 | 2 |
| 2 | 3 | 0.1500 | 0.5000 | 7 × 0.5000 = 3.5000 | 4 |
| 3 | 2 | 0.1000 | 0.6000 | 7 × 0.6000 = 4.2000 | 4 |
| 4 | 3 | 0.1500 | 0.7500 | 7 × 0.7500 = 5.2500 | 5 |
| 5 | 2 | 0.1000 | 0.8500 | 7 × 0.8500 = 5.9500 | 6 |
| 6 | 1 | 0.0500 | 0.9000 | 7 × 0.9000 = 6.3000 | 6 |
| 7 | 2 | 0.1000 | 1.0000 | 7 × 1.0000 = 7.0000 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 2 | 6 |
| 2 | 4 | 3 |
| 3 | 4 | 2 |
| 4 | 5 | 3 |
| 5 | 6 | 2 |
| 6 | 6 | 1 |
| 7 | 7 | 2 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 0 | 1 | 1 |
| 2 | 6 | 6 |
| 4 | 3 + 2 = 5 | 5 |
| 5 | 3 | 3 |
| 6 | 2 + 1 = 3 | 3 |
| 7 | 2 | 2 |
Equalized output image: replace every pixel r by its s.
| 1 | 2 | 4 | 7 | 0 |
| 2 | 1 | 3 | 1 | 5 |
| 5 | 2 | 1 | 4 | 1 |
| 7 | 6 | 3 | 1 | 4 |
| 2 | 4 | 5 | 7 | 0 |
| 4 | 2 | 4 | 2 | 6 |
| 6 | 4 | 2 | 5 | 2 |
| 7 | 6 | 4 | 2 | 5 |
Try it, step by step: Fall 25 quiz set C, every step.
A 3-bit 8×8 image has histogram counts {{0:2, 1:3, 2:5, 3:6, 4:9, 5:12, 6:14, 7:13}}. (i) Sketch the normalized histogram (ii) compute and sketch the equalized histogram (iii) sketch the transformation function curve.
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 64.
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 2 | 3 | 5 | 6 | 9 | 12 | 14 | 13 |
Check: Σ nk = 2 + 3 + 5 + 6 + 9 + 12 + 14 + 13 = 64.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 2 | 0.0312 | 0.0312 | 7 × 0.0312 = 0.2188 | 0 |
| 1 | 3 | 0.0469 | 0.0781 | 7 × 0.0781 = 0.5469 | 1 |
| 2 | 5 | 0.0781 | 0.1562 | 7 × 0.1562 = 1.0938 | 1 |
| 3 | 6 | 0.0938 | 0.2500 | 7 × 0.2500 = 1.7500 | 2 |
| 4 | 9 | 0.1406 | 0.3906 | 7 × 0.3906 = 2.7344 | 3 |
| 5 | 12 | 0.1875 | 0.5781 | 7 × 0.5781 = 4.0469 | 4 |
| 6 | 14 | 0.2188 | 0.7969 | 7 × 0.7969 = 5.5781 | 6 |
| 7 | 13 | 0.2031 | 1.0000 | 7 × 1.0000 = 7.0000 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 0 | 2 |
| 1 | 1 | 3 |
| 2 | 1 | 5 |
| 3 | 2 | 6 |
| 4 | 3 | 9 |
| 5 | 4 | 12 |
| 6 | 6 | 14 |
| 7 | 7 | 13 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 0 | 2 | 2 |
| 1 | 3 + 5 = 8 | 8 |
| 2 | 6 | 6 |
| 3 | 9 | 9 |
| 4 | 12 | 12 |
| 6 | 14 | 14 |
| 7 | 13 | 13 |
Try it, step by step: Fall 25 quiz set D: counts are given, so it starts at the table.
Histogram r = 0..7, n = [790, 1023, 850, 656, 329, 245, 122, 81]. (i) normalized histogram (ii) equalized histogram (iii) mapping of new gray levels into number of pixels (iv) transformation curve.
Here, as on slide 49, the PDF is rounded to 2 decimal places before the CDF.
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 4096.
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 790 | 1023 | 850 | 656 | 329 | 245 | 122 | 81 |
Check: Σ nk = 790 + 1023 + 850 + 656 + 329 + 245 + 122 + 81 = 4096.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 790 | 0.19 | 0.19 | 7 × 0.19 = 1.33 | 1 |
| 1 | 1023 | 0.25 | 0.44 | 7 × 0.44 = 3.08 | 3 |
| 2 | 850 | 0.21 | 0.65 | 7 × 0.65 = 4.55 | 5 |
| 3 | 656 | 0.16 | 0.81 | 7 × 0.81 = 5.67 | 6 |
| 4 | 329 | 0.08 | 0.89 | 7 × 0.89 = 6.23 | 6 |
| 5 | 245 | 0.06 | 0.95 | 7 × 0.95 = 6.65 | 7 |
| 6 | 122 | 0.03 | 0.98 | 7 × 0.98 = 6.86 | 7 |
| 7 | 81 | 0.02 | 1.00 | 7 × 1.00 = 7.00 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 1 | 790 |
| 1 | 3 | 1023 |
| 2 | 5 | 850 |
| 3 | 6 | 656 |
| 4 | 6 | 329 |
| 5 | 7 | 245 |
| 6 | 7 | 122 |
| 7 | 7 | 81 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 1 | 790 | 790 |
| 3 | 1023 | 1023 |
| 5 | 850 | 850 |
| 6 | 656 + 329 = 985 | 985 |
| 7 | 245 + 122 + 81 = 448 | 448 |
Try it, step by step: F22 with the PDF rounded to 2 places, as on slide 49.
4×4, 5-bit image. (i) histogram (ii) compute and sketch the normalized histogram (iii) compute and sketch the equalized histogram (iv) sketch the transformation curve.
Given: 5-bit image, so L = 25 = 32 and L − 1 = 31. Total pixels N = 16.
| 16 | 30 | 10 | 18 |
| 25 | 1 | 0 | 12 |
| 16 | 13 | 9 | 5 |
| 19 | 14 | 28 | 0 |
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| nk | 2 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 2 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
Check: Σ nk = 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 = 16.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 31; round off (.5 goes up). Only the intensities with non-zero occurrence are listed, as the slide says.
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 2 | 0.1250 | 0.1250 | 31 × 0.1250 = 3.8750 | 4 |
| 1 | 1 | 0.0625 | 0.1875 | 31 × 0.1875 = 5.8125 | 6 |
| 5 | 1 | 0.0625 | 0.2500 | 31 × 0.2500 = 7.7500 | 8 |
| 9 | 1 | 0.0625 | 0.3125 | 31 × 0.3125 = 9.6875 | 10 |
| 10 | 1 | 0.0625 | 0.3750 | 31 × 0.3750 = 11.6250 | 12 |
| 12 | 1 | 0.0625 | 0.4375 | 31 × 0.4375 = 13.5625 | 14 |
| 13 | 1 | 0.0625 | 0.5000 | 31 × 0.5000 = 15.5000 | 16 |
| 14 | 1 | 0.0625 | 0.5625 | 31 × 0.5625 = 17.4375 | 17 |
| 16 | 2 | 0.1250 | 0.6875 | 31 × 0.6875 = 21.3125 | 21 |
| 18 | 1 | 0.0625 | 0.7500 | 31 × 0.7500 = 23.2500 | 23 |
| 19 | 1 | 0.0625 | 0.8125 | 31 × 0.8125 = 25.1875 | 25 |
| 25 | 1 | 0.0625 | 0.8750 | 31 × 0.8750 = 27.1250 | 27 |
| 28 | 1 | 0.0625 | 0.9375 | 31 × 0.9375 = 29.0625 | 29 |
| 30 | 1 | 0.0625 | 1.0000 | 31 × 1.0000 = 31.0000 | 31 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 4 | 2 |
| 1 | 6 | 1 |
| 5 | 8 | 1 |
| 9 | 10 | 1 |
| 10 | 12 | 1 |
| 12 | 14 | 1 |
| 13 | 16 | 1 |
| 14 | 17 | 1 |
| 16 | 21 | 2 |
| 18 | 23 | 1 |
| 19 | 25 | 1 |
| 25 | 27 | 1 |
| 28 | 29 | 1 |
| 30 | 31 | 1 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 4 | 2 | 2 |
| 6 | 1 | 1 |
| 8 | 1 | 1 |
| 10 | 1 | 1 |
| 12 | 1 | 1 |
| 14 | 1 | 1 |
| 16 | 1 | 1 |
| 17 | 1 | 1 |
| 21 | 2 | 2 |
| 23 | 1 | 1 |
| 25 | 1 | 1 |
| 27 | 1 | 1 |
| 29 | 1 | 1 |
| 31 | 1 | 1 |
Equalized output image: replace every pixel r by its s.
| 16 | 30 | 10 | 18 |
| 25 | 1 | 0 | 12 |
| 16 | 13 | 9 | 5 |
| 19 | 14 | 28 | 0 |
| 21 | 31 | 12 | 23 |
| 27 | 6 | 4 | 14 |
| 21 | 16 | 10 | 8 |
| 25 | 17 | 29 | 4 |
Try it, step by step: F23 (5-bit): only the levels that occur get a table row.
4×4, 5-bit image. (i) histogram (ii) normalized histogram (iii) equalized histogram (iv) transformation curve.
Given: 5-bit image, so L = 25 = 32 and L − 1 = 31. Total pixels N = 16.
| 11 | 10 | 12 | 7 |
| 6 | 8 | 7 | 7 |
| 5 | 6 | 11 | 11 |
| 9 | 9 | 7 | 7 |
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| nk | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 5 | 1 | 2 | 1 | 3 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Check: Σ nk = 1 + 2 + 5 + 1 + 2 + 1 + 3 + 1 = 16.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 31; round off (.5 goes up). Only the intensities with non-zero occurrence are listed, as the slide says.
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 5 | 1 | 0.0625 | 0.0625 | 31 × 0.0625 = 1.9375 | 2 |
| 6 | 2 | 0.1250 | 0.1875 | 31 × 0.1875 = 5.8125 | 6 |
| 7 | 5 | 0.3125 | 0.5000 | 31 × 0.5000 = 15.5000 | 16 |
| 8 | 1 | 0.0625 | 0.5625 | 31 × 0.5625 = 17.4375 | 17 |
| 9 | 2 | 0.1250 | 0.6875 | 31 × 0.6875 = 21.3125 | 21 |
| 10 | 1 | 0.0625 | 0.7500 | 31 × 0.7500 = 23.2500 | 23 |
| 11 | 3 | 0.1875 | 0.9375 | 31 × 0.9375 = 29.0625 | 29 |
| 12 | 1 | 0.0625 | 1.0000 | 31 × 1.0000 = 31.0000 | 31 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 5 | 2 | 1 |
| 6 | 6 | 2 |
| 7 | 16 | 5 |
| 8 | 17 | 1 |
| 9 | 21 | 2 |
| 10 | 23 | 1 |
| 11 | 29 | 3 |
| 12 | 31 | 1 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 2 | 1 | 1 |
| 6 | 2 | 2 |
| 16 | 5 | 5 |
| 17 | 1 | 1 |
| 21 | 2 | 2 |
| 23 | 1 | 1 |
| 29 | 3 | 3 |
| 31 | 1 | 1 |
Equalized output image: replace every pixel r by its s.
| 11 | 10 | 12 | 7 |
| 6 | 8 | 7 | 7 |
| 5 | 6 | 11 | 11 |
| 9 | 9 | 7 | 7 |
| 29 | 23 | 31 | 16 |
| 6 | 17 | 16 | 16 |
| 2 | 6 | 29 | 29 |
| 21 | 21 | 16 | 16 |
Try it, step by step: SP22 (5-bit), every step.
(i) What is a histogram? Calculate it. (ii) normalized histogram (iii) equalized histogram (iv) transformation curve. 4×4, 5-bit image.
Histogram: a graphical representation of the distribution of pixel intensity values, h(rk) = nk.
Given: 5-bit image, so L = 25 = 32 and L − 1 = 31. Total pixels N = 16.
| 16 | 30 | 8 | 10 |
| 25 | 1 | 12 | 0 |
| 6 | 13 | 9 | 5 |
| 19 | 14 | 29 | 4 |
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| nk | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 |
Check: Σ nk = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 16.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 31; round off (.5 goes up). Only the intensities with non-zero occurrence are listed, as the slide says.
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 1 | 0.0625 | 0.0625 | 31 × 0.0625 = 1.9375 | 2 |
| 1 | 1 | 0.0625 | 0.1250 | 31 × 0.1250 = 3.8750 | 4 |
| 4 | 1 | 0.0625 | 0.1875 | 31 × 0.1875 = 5.8125 | 6 |
| 5 | 1 | 0.0625 | 0.2500 | 31 × 0.2500 = 7.7500 | 8 |
| 6 | 1 | 0.0625 | 0.3125 | 31 × 0.3125 = 9.6875 | 10 |
| 8 | 1 | 0.0625 | 0.3750 | 31 × 0.3750 = 11.6250 | 12 |
| 9 | 1 | 0.0625 | 0.4375 | 31 × 0.4375 = 13.5625 | 14 |
| 10 | 1 | 0.0625 | 0.5000 | 31 × 0.5000 = 15.5000 | 16 |
| 12 | 1 | 0.0625 | 0.5625 | 31 × 0.5625 = 17.4375 | 17 |
| 13 | 1 | 0.0625 | 0.6250 | 31 × 0.6250 = 19.3750 | 19 |
| 14 | 1 | 0.0625 | 0.6875 | 31 × 0.6875 = 21.3125 | 21 |
| 16 | 1 | 0.0625 | 0.7500 | 31 × 0.7500 = 23.2500 | 23 |
| 19 | 1 | 0.0625 | 0.8125 | 31 × 0.8125 = 25.1875 | 25 |
| 25 | 1 | 0.0625 | 0.8750 | 31 × 0.8750 = 27.1250 | 27 |
| 29 | 1 | 0.0625 | 0.9375 | 31 × 0.9375 = 29.0625 | 29 |
| 30 | 1 | 0.0625 | 1.0000 | 31 × 1.0000 = 31.0000 | 31 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 2 | 1 |
| 1 | 4 | 1 |
| 4 | 6 | 1 |
| 5 | 8 | 1 |
| 6 | 10 | 1 |
| 8 | 12 | 1 |
| 9 | 14 | 1 |
| 10 | 16 | 1 |
| 12 | 17 | 1 |
| 13 | 19 | 1 |
| 14 | 21 | 1 |
| 16 | 23 | 1 |
| 19 | 25 | 1 |
| 25 | 27 | 1 |
| 29 | 29 | 1 |
| 30 | 31 | 1 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 2 | 1 | 1 |
| 4 | 1 | 1 |
| 6 | 1 | 1 |
| 8 | 1 | 1 |
| 10 | 1 | 1 |
| 12 | 1 | 1 |
| 14 | 1 | 1 |
| 16 | 1 | 1 |
| 17 | 1 | 1 |
| 19 | 1 | 1 |
| 21 | 1 | 1 |
| 23 | 1 | 1 |
| 25 | 1 | 1 |
| 27 | 1 | 1 |
| 29 | 1 | 1 |
| 31 | 1 | 1 |
Equalized output image: replace every pixel r by its s.
| 16 | 30 | 8 | 10 |
| 25 | 1 | 12 | 0 |
| 6 | 13 | 9 | 5 |
| 19 | 14 | 29 | 4 |
| 23 | 31 | 12 | 16 |
| 27 | 4 | 17 | 2 |
| 10 | 19 | 14 | 8 |
| 25 | 21 | 29 | 6 |
Try it, step by step: F21 (5-bit), every step.
An image is histogram-equalized. Show that a second pass of histogram equalization produces exactly the same result as the first pass.
After the first pass, every input level rk has been moved to sk = round((L−1)·CDF(rk)). The order of levels is kept, since the CDF never decreases.
In the equalized image, the number of pixels at or below level sk is exactly the number of original pixels at or below rk (for the last rk that maps to sk). So the CDF of the new image at sk equals the old CDF at rk.
The second pass therefore computes round((L−1)·CDF) from the same CDF values and gets the same sk again. Each level maps to itself: the second mapping is the identity, and the image does not change.
Numeric check with the slide 36 result: equalized counts at s = 0, 2, 4, 5, 6, 7 are 1, 6, 5, 3, 3, 2. A second equalization gives new levels 0→0, 2→2, 4→4, 5→5, 6→6, 7→7, every level unchanged.
Equalize the given histogram: r = 0..7, n = [100, 90, 50, 20, 0, 0, 0, 0].
Given: 3-bit image, so L = 23 = 8 and L − 1 = 7. Total pixels N = 260.
Step 1, histogram h(rk) = nk: count the pixels at each gray level.
| rk | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| nk | 100 | 90 | 50 | 20 | 0 | 0 | 0 | 0 |
Check: Σ nk = 100 + 90 + 50 + 20 = 260.
Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up). Only the intensities with non-zero occurrence are listed, as the slide says.
| rk | Step 1: nk | Step 2: PDF | Step 3: CDF | Step 4: (L−1)·CDF | Step 5: sk |
|---|---|---|---|---|---|
| 0 | 100 | 0.3846 | 0.3846 | 7 × 0.3846 = 2.6923 | 3 |
| 1 | 90 | 0.3462 | 0.7308 | 7 × 0.7308 = 5.1154 | 5 |
| 2 | 50 | 0.1923 | 0.9231 | 7 × 0.9231 = 6.4615 | 6 |
| 3 | 20 | 0.0769 | 1.0000 | 7 × 1.0000 = 7.0000 | 7 |
Mapping the new gray levels into number of pixels:
| gray level rk | new gray level sk | no. of pixels nk |
|---|---|---|
| 0 | 3 | 100 |
| 1 | 5 | 90 |
| 2 | 6 | 50 |
| 3 | 7 | 20 |
Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.
| sk | pixels added | n(sk) |
|---|---|---|
| 3 | 100 | 100 |
| 5 | 90 | 90 |
| 6 | 50 | 50 |
| 7 | 20 | 20 |
Try it, step by step: the slide 60 class work.
Slide 46. Why another method? Histogram equalization has a disadvantage: it can produce only one type of output image. With histogram specification we can specify the shape of the histogram we want the output to have. It doesn't have to be uniform. Specification is a trial-and-error process: there are no rules for choosing the target histogram, and each enhancement task needs case-by-case analysis.
Slide 47. Example: you have a dull image and want it to look like a bright, high-contrast photo. Use the bright photo's histogram as the reference, and the result inherits its tonal style.
Slide 48. Definition: generate a processed image that has a specified histogram, i.e. convert the input image so that its histogram matches one that was arbitrarily specified. The mapping is found in three steps:
Get the histogram transformation function and make the output image follow the specified histogram pz = [0, 0, 0, 0.15, 0.20, 0.30, 0.20, 0.15].
Step 1, equalize the original histogram to get Hk.
| rk | nk | CDF | (L−1)·CDF | Hk | |
|---|---|---|---|---|---|
| 0 | 790 | 0.19 | 0.19 | 1.33 | 1 |
| 1 | 1023 | 0.25 | 0.44 | 3.08 | 3 |
| 2 | 850 | 0.21 | 0.65 | 4.55 | 5 |
| 3 | 656 | 0.16 | 0.81 | 5.67 | 6 |
| 4 | 329 | 0.08 | 0.89 | 6.23 | 6 |
| 5 | 245 | 0.06 | 0.95 | 6.65 | 7 |
| 6 | 122 | 0.03 | 0.98 | 6.86 | 7 |
| 7 | 81 | 0.02 | 1.00 | 7.00 | 7 |
Step 2, equalize the specified histogram to get Sk.
| zq | pz(zq) | CDF | (L−1)·CDF | Sk |
|---|---|---|---|---|
| 0 | 0.00 | 0.00 | 0.00 | 0 |
| 1 | 0.00 | 0.00 | 0.00 | 0 |
| 2 | 0.00 | 0.00 | 0.00 | 0 |
| 3 | 0.15 | 0.15 | 1.05 | 1 |
| 4 | 0.20 | 0.35 | 2.45 | 2 |
| 5 | 0.30 | 0.65 | 4.55 | 5 |
| 6 | 0.20 | 0.85 | 5.95 | 6 |
| 7 | 0.15 | 1.00 | 7.00 | 7 |
Step 3, relate the two. For each rk, take its Hk, find the S value closest to it, and map rk to that z. If two S values are equally close, take the higher one (slide 55). If several z share that S value, take the first such z.
| rk | Hk | closest S | map to z |
|---|---|---|---|
| 0 | 1 | 1 | 3 |
| 1 | 3 | 2 | 4 |
| 2 | 5 | 5 | 5 |
| 3 | 6 | 6 | 6 |
| 4 | 6 | 6 | 6 |
| 5 | 7 | 7 | 7 |
| 6 | 7 | 7 | 7 |
| 7 | 7 | 7 | 7 |
Output histogram: add the pixels that land on each z.
| z | pixels added | n(z) |
|---|---|---|
| 0 | – | 0 |
| 1 | – | 0 |
| 2 | – | 0 |
| 3 | 790 | 790 |
| 4 | 1023 | 1023 |
| 5 | 850 | 850 |
| 6 | 656 + 329 = 985 | 985 |
| 7 | 245 + 122 + 81 = 448 | 448 |
Compare with the slide: the actual output histogram has p(z) = 0.00, 0.00, 0.00, 0.19, 0.25, 0.21, 0.24, 0.11, close to the specified one, though not exact, because levels are discrete.
Try it, step by step: all three matching steps for slide 49: equalize the input, equalize the target, then relate them level by level.
Original histogram n = [8, 10, 10, 2, 12, 16, 4, 2]. Desired histogram n = [0, 0, 0, 0, 20, 20, 16, 8]. Find the mapping and the output histogram.
Step 1, equalize the original histogram to get Hk.
| rk | nk | CDF | (L−1)·CDF | Hk | |
|---|---|---|---|---|---|
| 0 | 8 | 0.12 | 0.12 | 0.84 | 1 |
| 1 | 10 | 0.16 | 0.28 | 1.96 | 2 |
| 2 | 10 | 0.16 | 0.44 | 3.08 | 3 |
| 3 | 2 | 0.03 | 0.47 | 3.29 | 3 |
| 4 | 12 | 0.19 | 0.66 | 4.62 | 5 |
| 5 | 16 | 0.25 | 0.91 | 6.37 | 6 |
| 6 | 4 | 0.06 | 0.97 | 6.79 | 7 |
| 7 | 2 | 0.03 | 1.00 | 7.00 | 7 |
Step 2, equalize the specified histogram to get Sk.
| zq | specified n | pz(zq) | CDF | (L−1)·CDF | Sk |
|---|---|---|---|---|---|
| 0 | 0 | 0.00 | 0.00 | 0.00 | 0 |
| 1 | 0 | 0.00 | 0.00 | 0.00 | 0 |
| 2 | 0 | 0.00 | 0.00 | 0.00 | 0 |
| 3 | 0 | 0.00 | 0.00 | 0.00 | 0 |
| 4 | 20 | 0.31 | 0.31 | 2.17 | 2 |
| 5 | 20 | 0.31 | 0.62 | 4.34 | 4 |
| 6 | 16 | 0.25 | 0.87 | 6.09 | 6 |
| 7 | 8 | 0.12 | 1.00 | 7.00 | 7 |
Step 3, relate the two. For each rk, take its Hk, find the S value closest to it, and map rk to that z. If two S values are equally close, take the higher one (slide 55). If several z share that S value, take the first such z.
| rk | Hk | closest S | map to z |
|---|---|---|---|
| 0 | 1 | 2 | 4 |
| 1 | 2 | 2 | 4 |
| 2 | 3 | 4 | 5 |
| 3 | 3 | 4 | 5 |
| 4 | 5 | 6 | 6 |
| 5 | 6 | 6 | 6 |
| 6 | 7 | 7 | 7 |
| 7 | 7 | 7 | 7 |
Output histogram: add the pixels that land on each z.
| z | pixels added | n(z) |
|---|---|---|
| 0 | – | 0 |
| 1 | – | 0 |
| 2 | – | 0 |
| 3 | – | 0 |
| 4 | 8 + 10 = 18 | 18 |
| 5 | 10 + 2 = 12 | 12 |
| 6 | 12 + 16 = 28 | 28 |
| 7 | 4 + 2 = 6 | 6 |
Try it, step by step: slide 55, including the ties that go to the higher S.
What is the histogram of an image? Can you reconstruct the image from the histogram? How does the histogram differ for a dark, bright, low-contrast or high-contrast image? [1+1+2]
Histogram: a graphical representation of the distribution of pixel intensity values in an image. For gray levels in [0, L−1] it is the discrete function h(rk) = nk, where nk is the number of pixels with gray level rk.
Reconstruction: No. A histogram holds only statistical information (how many pixels have each value), not the location of the pixels. Different images can have the same histogram, e.g. a half-black/half-white image and a checkerboard with the same numbers of black and white pixels.
Four types [draw the four small histograms]:
What is the histogram of an image? Explain the four basic intensity characteristics of an image and their corresponding histograms.
Write the definition and h(rk) = nk as above, then the four types with their four sketches. Add the meaning of each:
What is the histogram of an image? How does the histogram differ for dark, bright, low-contrast and high-contrast images of the same scene? Write the steps of the histogram equalization algorithm. [1+2+2]
Definition and four types as above. Algorithm (input: image f with L levels):
How do you generate an image histogram? What does an image histogram say? [3+3]
Generate: (1) find the number of gray levels L = 2k and make one bin per level 0 … L−1; (2) scan the image and, for each pixel with value rk, add 1 to bin h(rk); (3) plot nk against rk as bars. Σ h = total number of pixels.
Example (slide 7, 3-bit 4×4): h = [1, 1, 3, 5, 1, 2, 1, 2].
What it says: how many pixels have each intensity, i.e. the tonal distribution. From its shape we can tell whether the image is dark, bright, low- or high-contrast; judge the overall quality and the possibility of enhancement; check whether the image was scanned properly; and choose a threshold for object detection and segmentation. It gives only statistical information and no indication of pixel locations.
What is the histogram of an image? Two 20×20 images have equal numbers of black (0) and white (1) pixels. Are their histograms identical? Explain. [2+4]
Definition: as above, h(rk) = nk.
Each image has 20 × 20 = 400 pixels: 200 black and 200 white. So for both images h(0) = 200 and h(1) = 200.
Yes, the histograms are identical, even if one image is half black / half white and the other is a checkerboard. A histogram records only how many pixels have each value, not where they are. So the same histogram can come from different images, and an image cannot be reconstructed from its histogram.
For continuous intensities the equalizing transformation is s = T(r) = (L − 1) ∫0r pr(w) dw. In the discrete case it becomes s = T(r) = (L − 1) Σ p(rj) for j = 0 … k, i.e. (L − 1) times the CDF. This is why the algorithm multiplies the CDF by L − 1.
| thing | formula / rule |
|---|---|
| histogram | h(rk) = nk |
| normalized | p(rk) = nk/N, Σ = 1 |
| sliding | add a constant: brighter or darker, same shape |
| stretching | g = 255(f − MIN)/(MAX − MIN), same shape |
| equalization | sk = round((L−1)·CDF(rk)) |
| matching | equalize input → H, equalize target → S, map H to closest S |