All 12 questions from quizzes 1–4 (sets C and D), written the way you would write them in the answer script. Every question has a simulator under it: step through it or change the numbers.
Discuss logarithmic transformations for image enhancement.
Definition. The log transformation is a basic intensity transformation:
r = input gray level, s = output gray level, c = a constant, r ≥ 0. The 1 is added so that log 0 never occurs. To map 0…255 onto 0…255, c = 255 / log(256) = 105.89.
Shape. Draw this graph in the answer script:
The curve lies above the diagonal. It is steep for small r and flat for large r.
Properties.
Worked values (c = 105.89):
| r | c·log(1 + r) | s |
|---|---|---|
| 10 | 105.89 × log(11) = 110.3 | 110 |
| 50 | 105.89 × log(51) = 180.8 | 181 |
| 100 | 105.89 × log(101) = 212.2 | 212 |
| 255 | 105.89 × log(256) = 255.0 | 255 |
The input band 0–50 (20% of the range) becomes 0–181 (71%). The band 100–255 shrinks to 212–255.
Application. Use it when the input has a very large dynamic range that the display cannot show. The standard example is the Fourier spectrum, whose values run from 0 to about 1.5×106. On a display only the bright centre shows; after the log transform the whole spectrum is visible. That is why it is called dynamic-range compression.
Inverse log, s = 10r/c − 1, does the opposite: it expands the bright values and compresses the dark ones.
Try it: move r and watch where it lands on the curve. Notice how a small step in the dark end moves s a lot, and the same step in the bright end hardly moves it.
A medical X-ray image (8-bit) needs its bone structures in the range [120, 200] enhanced. Apply gray-level slicing with both approaches. (i) Write the transformation functions [4] (ii) Show the mapping for pixel values 100, 150 and 220 [4] (iii) Sketch the transformation curves [3].
Given: 8-bit, so L − 1 = 255. Band of interest A = 120, B = 200. Highlight level = 255.
(i) Transformation functions
Approach 1, without background (other levels suppressed):
Approach 2, with background (other levels preserved):
(ii) Mapping
| r | inside [120, 200]? | Approach 1 s | Approach 2 s |
|---|---|---|---|
| 100 | no | 0 | 100 |
| 150 | yes | 255 | 255 |
| 220 | no | 0 | 220 |
r = 100 is below the band: approach 1 gives 0, approach 2 keeps 100. r = 150 is inside: both give 255. r = 220 is above: approach 1 gives 0, approach 2 keeps 220.
(iii) Curves
Result: approach 1 shows only the bones, white on black. Approach 2 shows the bones in white with the rest of the X-ray still visible.
Try it: type any pixel value, or change the band, and read off both approaches. The dot moves on both curves.
How many shades of gray are possible in a 10-bit grayscale image? Show the numeric range. Write the expression for intensity resolution.
Intensity resolution = number of gray levels a pixel can take. With k bits per pixel:
Here k = 10, so L = 210 = 1024 shades.
Range: 0 to L − 1 = 0 to 1023 (0 = black, 1023 = white).
Try it: slide k and read off L = 2k and the range. The strip shows the gray steps, which become visible bands at small k.
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.
Try it: pick an image type. The page makes a small image of that type and counts its histogram from scratch, the same way as in steps 1–3.
Explain the four basic types of intensity characteristics of an image and their corresponding histograms.
The histogram of a digital image with gray levels 0 … L−1 is h(rk) = nk, the number of pixels with gray level rk. Its shape shows the four basic types:
Histogram equalization tries to turn types 1–3 into type 4.
Try it: click each type: a fresh random image of that kind and its counted histogram. Compare with the four sketches.
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.
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.
Histogram. For a digital image with gray levels in [0, L−1], the histogram is the discrete function
where nk is the number of pixels with gray level rk. It is drawn as bars of nk against rk. The normalized histogram is p(rk) = nk / MN.
The two images. Each has 20 × 20 = 400 pixels, and equal numbers of black and white, so 200 black and 200 white. For both images:
Yes, the histograms are identical, even if one image is half black and half white and the other is a checkerboard. A histogram records only how many pixels have each value, not where they are. It has no spatial information.
So different images can have the same histogram, and an image cannot be rebuilt from its histogram.
Try it: rearrange the same 200 black and 200 white pixels. The picture changes; the counted histogram never does.
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.
What are the two principal approaches to image segmentation? Why is a Laplacian filter typically combined with a Gaussian smoothing filter (LoG operator) before performing edge detection in noisy environments?
Two approaches (based on two basic properties of intensity values):
Why Gaussian + Laplacian (LoG).
Small proof (a noisy step, 2nd derivative f(x+1) + f(x−1) − 2f(x)):
| signal | 2nd derivative | zero crossings | |
|---|---|---|---|
| noisy | 10 13 9 12 10 11 40 38 41 39 42 40 | -7 7 -5 3 28 -31 5 -5 5 -5 | 8 |
| smoothed [1 2 1]/4 | 10 11 11 11 11 18 32 39 40 40 41 40 | -1 0 0 7 7 -7 -6 -1 1 -2 | 3 |
Noisy: 8 sign changes, almost all false. Smoothed: the big one (7 → −7) sits at the real step, and the leftover small ones are weak, so a threshold on the jump drops them.
Try it, step by step: 2nd derivative of the NOISY step: the signs flip again and again in the flat part.
Try it, step by step: the same step after Gaussian-like smoothing: one strong +/− pair at the real edge.
For the boundary in the grid figure (anticlockwise), compute the 8-directional chain code that is (i) invariant to the starting point; (ii) invariant to both the starting point and rotation.
Step 1 · chain code. Start at the top pixel (1,2) and walk anticlockwise round the boundary. Each move to the next boundary pixel gets the number of its direction (8-direction compass: 0 = right, then counterclockwise).
| move | from → to | direction | code |
|---|---|---|---|
| 1 | (1,2) → (2,1) | down-left ↙ | 5 |
| 2 | (2,1) → (3,0) | down-left ↙ | 5 |
| 3 | (3,0) → (4,1) | down-right ↘ | 7 |
| 4 | (4,1) → (5,1) | down ↓ | 6 |
| 5 | (5,1) → (6,2) | down-right ↘ | 7 |
| 6 | (6,2) → (5,3) | up-right ↗ | 1 |
| 7 | (5,3) → (4,4) | up-right ↗ | 1 |
| 8 | (4,4) → (3,4) | up ↑ | 2 |
| 9 | (3,4) → (2,3) | up-left ↖ | 3 |
| 10 | (2,3) → (1,2) | up-left ↖ | 3 |
Step 2 · start-point invariance (shape number of slide 18). The boundary is a loop, so any digit can be the first. Write the code from every start (circular shifts) and pick the one that reads as the smallest number.
| from 1 | 5 | 5 | 7 | 6 | 7 | 1 | 1 | 2 | 3 | 3 |
| from 2 | 5 | 7 | 6 | 7 | 1 | 1 | 2 | 3 | 3 | 5 |
| from 3 | 7 | 6 | 7 | 1 | 1 | 2 | 3 | 3 | 5 | 5 |
| from 4 | 6 | 7 | 1 | 1 | 2 | 3 | 3 | 5 | 5 | 7 |
| from 5 | 7 | 1 | 1 | 2 | 3 | 3 | 5 | 5 | 7 | 6 |
| from 6 | 1 | 1 | 2 | 3 | 3 | 5 | 5 | 7 | 6 | 7 |
| from 7 | 1 | 2 | 3 | 3 | 5 | 5 | 7 | 6 | 7 | 1 |
| from 8 | 2 | 3 | 3 | 5 | 5 | 7 | 6 | 7 | 1 | 1 |
| from 9 | 3 | 3 | 5 | 5 | 7 | 6 | 7 | 1 | 1 | 2 |
| from 10 | 3 | 5 | 5 | 7 | 6 | 7 | 1 | 1 | 2 | 3 |
Step 3 · circular first difference (CFD). Slide 22 rule: CFDi = (ci+1 − ci) mod 8; the last digit wraps round to the first. This removes rotation.
| i | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| this ci | 5 | 5 | 7 | 6 | 7 | 1 | 1 | 2 | 3 | 3 |
| next ci+1 | 5 | 7 | 6 | 7 | 1 | 1 | 2 | 3 | 3 | 5 |
| next − this | 0 | 2 | -1 | 1 | -6 | 0 | 1 | 1 | 0 | 2 |
| mod 8 = CFD | 0 | 2 | 7 | 1 | 2 | 0 | 1 | 1 | 0 | 2 |
Step 4 · normalise (NCFD). Smallest circular shift of the CFD. This removes the start point too.
| from 1 | 0 | 2 | 7 | 1 | 2 | 0 | 1 | 1 | 0 | 2 |
| from 2 | 2 | 7 | 1 | 2 | 0 | 1 | 1 | 0 | 2 | 0 |
| from 3 | 7 | 1 | 2 | 0 | 1 | 1 | 0 | 2 | 0 | 2 |
| from 4 | 1 | 2 | 0 | 1 | 1 | 0 | 2 | 0 | 2 | 7 |
| from 5 | 2 | 0 | 1 | 1 | 0 | 2 | 0 | 2 | 7 | 1 |
| from 6 | 0 | 1 | 1 | 0 | 2 | 0 | 2 | 7 | 1 | 2 |
| from 7 | 1 | 1 | 0 | 2 | 0 | 2 | 7 | 1 | 2 | 0 |
| from 8 | 1 | 0 | 2 | 0 | 2 | 7 | 1 | 2 | 0 | 1 |
| from 9 | 0 | 2 | 0 | 2 | 7 | 1 | 2 | 0 | 1 | 1 |
| from 10 | 2 | 0 | 2 | 7 | 1 | 2 | 0 | 1 | 1 | 0 |
Try it, step by step: F25 quiz boundary. Set “Normalise” to CC for part (i), CFD for part (ii).
Give the equations of erosion and dilation; describe opening and closing. / Describe two basic morphological operations with equations, effects and applications. / Define dilation and erosion in binary images; how do they affect object size and shape?
Erosion A ⊖ B = {z | (B)z ⊆ A}: a pixel stays 1 only where the SE fits inside the object. Effects: shrinks foreground objects (removes the outer layer), removes objects smaller than B, smooths the boundary by cutting spikes, can split touching objects, enlarges holes. Uses: removing isolated noise pixels, separating touching coins before counting, boundary extraction β(A) = A − (A ⊖ B).
Dilation A ⊕ B = {z | (B̂)z ∩ A ≠ ∅}: a pixel becomes 1 where the SE hits the object. Effects: expands foreground objects (adds an outer layer), fills small holes, bridges gaps, joins nearby objects, smooths intrusions. Uses: repairing broken characters in low-resolution text, filling holes, edge detection (A ⊕ B) − A.
Size and shape: erosion makes objects smaller and thinner (size shrinks by the SE radius); dilation makes them larger and thicker. The SE's shape decides the direction: a vertical SE acts only vertically, a disk rounds corners.
Opening (A ⊖ B) ⊕ B removes small objects and thin bridges, keeps size. Closing (A ⊕ B) ⊖ B fills small holes and gaps, keeps size. Both are idempotent.
Try it, step by step: a 4×4 square with a spike and a lone noise pixel. Erosion: the square shrinks to 2×2, the spike and noise vanish. Switch to dilation: everything grows by one pixel all round.
Construct a 6×6 binary image A and a 3×3 structuring element B. Using fundamental morphological operations, formulate an edge-detection algorithm for A with B, and demonstrate the procedure systematically with mathematical expressions.
Choose A = a 4×4 square in a 6×6 image; B = 3×3 square, origin at the centre.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
Algorithm (inner boundary): 1. erode: A ⊖ B = {z | (B)z ⊆ A}; 2. subtract: β(A) = A − (A ⊖ B) = A ∩ (A ⊖ B)c.
Step 1: B fits only where the pixel and all 8 neighbours are 1, i.e. the inner 2×2. Step 2: removing those from A leaves the one-pixel ring.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
Alternative (outer edge): (A ⊕ B) − A, dilation then subtraction, gives the ring just outside the square:
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
Try it, step by step: both edge algorithms: erode then subtract, or dilate then subtract.