optional · CSS study notes
Image Histogram and Enhancement
CSS Optional — Paper-II, Section-B · P-II.V.VI · Syllabus: Image Histogram; Image Enhancement (Contrast, Smoothing, Sharpening). The highest-yield DIP topic — histogram theory in 2017, histogram-equalization numerical and mean vs median filters in 2018.
1. Image Histogram
- For an image with L levels, the histogram is
h(r_k) = n_k— the number of pixels with intensity r_k. The normalized histogramp(r_k) = n_k / MNestimates the probability of each level (values sum to 1). - Reading a histogram:
| Histogram shape | Image appearance |
|---|---|
| Bunched at the left (low values) | Dark image |
| Bunched at the right | Bright / washed-out image |
| Narrow, in the middle | Low contrast (dull, grey) |
| Spread across the full range | High contrast |
| Two clear peaks (bimodal) | Object and background — ideal for thresholding |
- Applications (2017 asked this): contrast diagnosis, histogram equalization/matching, choosing a threshold for segmentation, camera auto-exposure, image compression statistics, content-based image retrieval.
- A histogram carries no spatial information — very different images can share the same histogram.
2. Enhancement: Spatial vs Frequency Domain
Enhancement makes an image more suitable for a specific purpose — it is subjective (judged by the viewer), unlike restoration, which is objective.
- Spatial domain: operate on pixels directly — point operations and neighbourhood (mask) filtering.
- Frequency domain: take the Fourier transform, modify frequencies, inverse transform.
3. Contrast Enhancement — Point (Intensity) Transformations
| Transformation | Formula | Use |
|---|---|---|
| Negative | s = L − 1 − r | Viewing white/grey detail in dark regions (mammograms) |
| Log | s = c·log(1 + r) | Compress a huge dynamic range (display a Fourier spectrum) |
| Power-law (gamma) | s = c·r^γ | γ < 1 brightens dark images; γ > 1 darkens washed-out ones; monitor gamma correction |
| Contrast stretching | s = (r − rmin)(L − 1)/(rmax − rmin) | Expand a narrow range to the full 0–255 |
| Thresholding | s = L−1 if r > T, else 0 | Extreme stretching → binary image |
| Intensity-level slicing | Highlight a range [A, B] | Emphasize features (e.g. blood vessels in angiograms) |
| Bit-plane slicing | Separate the 8 bit planes | Analyse the contribution of each bit; compression; watermarking in low planes |
4. Histogram Equalization
- Goal: spread intensities over the full range so the output histogram is approximately uniform → better contrast, automatically (no parameters).
- Transformation:
s_k = (L − 1) · Σ(j=0..k) p_r(r_j)— the scaled cumulative distribution function (CDF), then round to the nearest integer. - Steps: (1) count n_k, (2) p_k = n_k/MN, (3) cumulative sum, (4) × (L − 1), (5) round, (6) remap every pixel, (7) build the new histogram by merging counts that map to the same s.
- Limitations: discrete output is not perfectly flat; can amplify noise in flat regions; may over-enhance and look unnatural.
- Histogram matching (specification): map to a specified target histogram instead of a flat one.
- Local / adaptive equalization (e.g. CLAHE): equalize small tiles with a clip limit — enhances local detail without blowing up noise; widely used in medical imaging.
5. Spatial Filtering Basics
A mask (kernel) slides over the image; each output pixel = Σ(mask weight × pixel under it). Correlation uses the mask as is; convolution rotates it by 180° first (identical for symmetric masks). Border handling: zero padding, replicate or mirror.
6. Smoothing (Low-Pass) Filters
| Filter | Type | Mask / rule | Notes |
|---|---|---|---|
| Box (mean / average) | Linear | (1/9)·[1 1 1; 1 1 1; 1 1 1] | Reduces Gaussian noise; blurs edges |
| Weighted average / Gaussian | Linear | (1/16)·[1 2 1; 2 4 2; 1 2 1] | Less blur than box; centre weighted most |
| Median | Non-linear (order statistic) | Replace with median of window | Best for salt-and-pepper noise; preserves edges |
| Min / Max | Non-linear | Min or max of window | Max removes pepper (dark) noise; min removes salt (bright) noise |
Mean vs Median (CSS 2018):
| Point | Mean filter | Median filter |
|---|---|---|
| Operation | Average of the neighbourhood | Middle value of the sorted neighbourhood |
| Linearity | Linear | Non-linear |
| Best against | Gaussian / uniform noise | Impulse (salt-and-pepper) noise |
| Edges | Blurred | Largely preserved |
| Outliers | A single outlier shifts the result | Outliers are ignored |
| Output values | Can create new values not in the image | Always an existing value |
| Cost | Cheap (sum) | Costlier (sorting) |
7. Sharpening (High-Pass) Filters
- Purpose: highlight fine detail and edges (the opposite of smoothing); based on derivatives.
- Laplacian (second derivative):
[0 1 0; 1 −4 1; 0 1 0]or 8-neighbour[1 1 1; 1 −8 1; 1 1 1]. Sharpened image: g = f − ∇²f (when the centre coefficient is negative). - Unsharp masking: blur the image, subtract the blur from the original to get a mask, add it back:
g = f + k·(f − f_blur). k = 1 → unsharp masking; k > 1 → high-boost filtering. (Originated in the printing industry.) - Gradient (first derivative) — Sobel/Prewitt: mostly used for edge detection (see Point, Line, Edge and Boundary Detection).
- Sharpening amplifies noise — smooth first if the image is noisy.
8. Frequency-Domain Enhancement
| Filter | Low-pass (smooth) | High-pass (sharpen) | Note |
|---|---|---|---|
| Ideal | ILPF | IHPF | Sharp cutoff → RINGING artefacts |
| Butterworth (order n) | BLPF | BHPF | Smooth transition; little ringing at low order |
| Gaussian | GLPF | GHPF | No ringing |
Homomorphic filtering: uses f = i · r; take the log, suppress low frequencies (illumination) and boost high ones (reflectance) → corrects uneven lighting while enhancing detail.
📐 Worked Numericals
N1 — Histogram equalization (64 × 64, 3-bit, L = 8; the method CSS 2018 asked for):
| r_k | n_k | p_k | CDF | 7 × CDF | s_k |
|---|---|---|---|---|---|
| 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 |
Equalized histogram: s1 = 790, s3 = 1023, s5 = 850, s6 = 985, s7 = 448 (sum 4096 ✓). Wider spread → higher contrast; not perfectly flat.
N2 — Contrast stretching: 8-bit image occupying 50–150. For r = 100: s = (100 − 50) × 255 / 100 = 127.5 → 128; r = 50 → 0; r = 150 → 255.
N3 — Negative: 8-bit pixel 70 → s = 255 − 70 = 185.
N4 — Gamma: normalized r = 0.25, γ = 0.5 → s = 0.5 (brighter); γ = 2 → s = 0.0625 (darker).
N5 — Mean vs median on window {10, 12, 11, 255, 13, 12, 0, 11, 12}:
- Mean = 336 / 9 ≈ 37.3 — the salt (255) and pepper (0) pull the value far from the true ≈ 12.
- Sorted: 0, 10, 11, 11, 12, 12, 12, 13, 255 → median = 12 — noise rejected.
N6 — Box filter: window 10 20 30 / 40 50 60 / 70 80 90 → mean = 450/9 = 50.
N7 — Laplacian sharpening: centre f = 50, four neighbours all 30. ∇²f (4-neighbour mask) = 30×4 − 4×50 = −80 → g = f − ∇²f = 50 + 80 = 130 → the bright detail is emphasized.
N8 — High-boost: f = 100, f_blur = 90, k = 2 → g = 100 + 2 × 10 = 120.
🎯 CSS Exam Angle
- "Define histogram / equalization + applications" (2017): definition + normalized formula, 4-row "shape → appearance" table, CDF formula, 4–5 applications.
- "Perform histogram equalization" (2018): draw the 6-column table above — it is the whole answer. Finish with the new histogram and one line on why it isn't perfectly flat.
- "Mean vs median" (2018): the comparison table + the N5 example makes a complete, memorable answer.
📌 Past CSS Paper Frequency
| Year | Question |
|---|---|
| 2017 | Define image histogram; what is histogram equalization; applications in image processing |
| 2018 | Perform histogram equalization on an 8-bit image (numerical) |
| 2018 | In the context of image smoothing, differences between mean and median filters |
⚠️ MCQ Traps
- Histogram equalization uses the cumulative distribution (CDF), not the plain histogram.
- Discrete equalization does not give a perfectly flat histogram.
- Median is non-linear; mean/Gaussian are linear. Median is best for salt-and-pepper.
- Smoothing masks' weights sum to 1; sharpening/derivative masks' weights sum to 0.
- γ < 1 brightens; γ > 1 darkens (for normalized input).
- Ideal filters cause ringing; Gaussian filters do not.
- Enhancement is subjective; restoration is objective (model-based).
✅ Self-Check (with Answers)
Q1. Define histogram and normalized histogram.
Ans: Histogram h(r_k) = n_k, the number of pixels at each gray level r_k. Normalized histogram p(r_k) = n_k / MN, the estimated probability of each level; its values sum to 1.
Q2. What does a narrow histogram in the middle of the range indicate, and what is the fix?
Ans: A low-contrast (dull, grey) image. Fix with contrast stretching or histogram equalization to spread values over 0–255.
Q3. Equalize a 2-bit image (L = 4) with counts n = {6, 6, 2, 2} (16 pixels).
Ans: p = {0.375, 0.375, 0.125, 0.125}; CDF = {0.375, 0.75, 0.875, 1.0}; × 3 = {1.125, 2.25, 2.625, 3} → s = {1, 2, 3, 3}. New histogram: level 1 = 6, level 2 = 6, level 3 = 4.
Q4. Why does sharpening use derivatives, and what is its drawback?
Ans: Edges and fine detail are places of rapid intensity change, which derivatives (gradient, Laplacian) highlight. Drawback: derivatives also amplify noise, so noisy images should be smoothed first.
Q5. What is the difference between unsharp masking and high-boost filtering?
Ans: Both compute g = f + k(f − f_blur). Unsharp masking uses k = 1; high-boost uses k > 1, adding more of the detail mask and also keeping more of the original's brightness.
Q6. Which frequency-domain low-pass filter causes ringing, and which does not?
Ans: The ideal low-pass filter (sharp cutoff) causes ringing; the Gaussian low-pass filter causes none; Butterworth sits in between depending on its order.
Q7. Why is histogram equalization applied on the I channel of HSI, not separately on R, G, B?
Ans: Equalizing R, G and B independently changes their ratios and shifts hues. Equalizing only intensity improves contrast while leaving hue and saturation unchanged.
📜 Past-Paper Questions & MCQs (CSS 2016–2026)
2017 · Paper-II · Q7(a), 2020 · Q7(a), 2025 · Q7(c) · 8, 6 and 8 marks
Q. Define an image histogram. What is meant by histogram equalisation? Explain the process and discuss its applications.
Ans.
- Image histogram: a plot (or table) of the number of pixels at each intensity level, h(rₖ) = nₖ. The normalised form is p(rₖ) = nₖ / n, the probability of level rₖ. It shows brightness and contrast: a histogram bunched to the left means a dark image, to the right a bright image, and a narrow one a low-contrast image.
- Histogram equalisation transforms intensities so that the histogram becomes as flat (uniform) as possible, which spreads the used levels over the whole range and increases contrast.
- Process:
- Step 1: Compute the histogram nₖ and p(rₖ) = nₖ / n.
- Step 2: Compute the cumulative distribution (CDF): Σⱼ≤ₖ p(rⱼ).
- Step 3: Map each level: sₖ = round( (L − 1) × CDF(rₖ) ), with L levels (256 for 8 bits).
- Step 4: Replace every pixel of level rₖ with sₖ.
- Applications: enhancing low-contrast photographs, medical images (X-ray, CT), satellite and aerial images, and as preprocessing before segmentation or recognition.
- Limits: may over-enhance noise, and on colour images applying it to each RGB channel separately causes colour distortion (equalise the intensity or I/V channel instead).
2018 · Paper-II · Q7(A) · 8 marks
Q. Perform histogram equalisation on the 8-bit 5 × 5 image whose rows have the values 5, 10, 30, 100, 100 (each row repeated across the 5 columns).
Ans.
- Pixel counts: the image has 25 pixels. Level 5 has 5 pixels, 10 has 5, 30 has 5 and 100 has 10.
- L = 256, so L − 1 = 255.
| Level r | Count n | p = n / 25 | CDF | s = round(255 × CDF) |
|---|---|---|---|---|
| 5 | 5 | 0.2 | 0.2 | 51 |
| 10 | 5 | 0.2 | 0.4 | 102 |
| 30 | 5 | 0.2 | 0.6 | 153 |
| 100 | 10 | 0.4 | 1.0 | 255 |
- Equalised image: 5 → 51, 10 → 102, 30 → 153, 100 → 255 (rows 51, 102, 153, 255, 255).
- (An alternative formula that subtracts the minimum CDF gives 0, 64, 128, 255.)
2018 · Paper-II · Q6(B) · 6 marks
Q. In the context of image smoothing, discuss the differences between mean and median filters.
Ans.
| Basis | Mean filter | Median filter |
|---|---|---|
| Operation | Replaces a pixel by the average of its neighbourhood (linear) | Replaces a pixel by the median of its neighbourhood (non-linear) |
| Best against | Gaussian (random) noise | Salt-and-pepper (impulse) noise |
| Edges | Blurs edges and details | Preserves edges much better |
| Outliers | An extreme value changes the average, and spreads into neighbours | Extreme values are ignored |
| Cost | Fast (convolution) | Slower (sorting the neighbourhood) |
2023 · Paper-II · Q7(b)(c) · 5 + 5 marks
Q. What effect would setting to zero the lower-order bit planes have on the histogram of an image? What if the higher-order bit planes are set to zero instead?
Ans.
- Lower-order bit planes set to zero: fine intensity detail is lost, and the number of distinct grey levels falls. The histogram keeps its overall shape but becomes a sparse comb of spikes (many levels have zero count, and neighbouring levels merge into one). The image looks nearly the same but may show false contouring.
- Higher-order bit planes set to zero (for example the MSB): the image loses most of its brightness information. All pixel values are squeezed into the lower part of the range (the MSB set to zero leaves only 0–127), so the image becomes darker with much less contrast, and the histogram is compressed and folded toward the dark end.
MCQs
2025 P-II · Q7. What is the method used to generate a processed image that has a specified histogram?
- (A) Histogram linearization
- (B) Histogram equalization
- (C) Histogram matching ✅
- (D) Histogram processing
- Answer: (C) Histogram matching.
- Why: histogram matching (specification) transforms an image so that its histogram follows a chosen shape. Equalisation always aims for a flat histogram, so it cannot produce a specified one.
2026 P-II · Q3. In histogram equalization, applying the technique to each RGB channel independently often causes:
- (A) Improved colour constancy
- (B) Better noise suppression
- (C) Colour distortions due to channel imbalance ✅
- (D) None of these
- Answer: (C).
- Why: each channel is stretched by a different mapping, so the ratio between R, G and B changes and the colours shift. The better approach is to equalise only the intensity (I or V) channel of a HSI or HSV image.
2024 P-II · Q14. Dynamic range in image processing is:
- (A) The span of wavelengths covered by a particular band in a multispectral image
- (B) The maximum or minimum values present in an image
- (C) The range of values spanned by the grey scale ✅
- (D) None of these
- Answer: (C).
- Why: dynamic range is the ratio of the largest to the smallest intensity in an image or sensor (the span of grey levels it can represent). (A) describes spectral resolution of a band, and (B) gives just the two extreme values, not the range.