CSE 4227 · Fall 2025 · quizzes 1–4, all sets we have

Every Fall 2025 quiz question, answered

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.

Quiz 1 (C) Q1 · Logarithmic transformation

6 marks · deck 04
Fall 25 Quiz 1 (set C) Q16 marks

Discuss logarithmic transformations for image enhancement.

Definition. The log transformation is a basic intensity transformation:

s = c · log(1 + r)

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:

0501001502002550128255r (input)s (output)loginverse log10→11050→181100→212
s = c·log(1 + r), c = 105.89 (8-bit). Dashed: identity s = r.

The curve lies above the diagonal. It is steep for small r and flat for large r.

Properties.

  • For low input values the range is expanded: dark regions are spread out and their details become visible.
  • For high input values the range is compressed: bright regions are squeezed together.

Worked values (c = 105.89):

rc·log(1 + r)s
10105.89 × log(11) = 110.3110
50105.89 × log(51) = 180.8181
100105.89 × log(101) = 212.2212
255105.89 × log(256) = 255.0255

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.

Quiz 1 (C) Q2(a) · Gray-level slicing, X-ray bones

11 marks · deck 04
Fall 25 Quiz 2(a)11 marks

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):

s =
255
if 120 ≤ r ≤ 200
0
otherwise

Approach 2, with background (other levels preserved):

s =
255
if 120 ≤ r ≤ 200
r
otherwise

(ii) Mapping

rinside [120, 200]?Approach 1 sApproach 2 s
100no0100
150yes255255
220no0220

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

01202002550255r (input)s (output)
Approach 1: 0, jump to 255 on [120, 200], back to 0.
01202002550255r (input)s (output)
Approach 2: s = r, lifted to 255 on [120, 200].

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.

Quiz 1 (C) Q2(b) · 10-bit shades and intensity resolution

3 marks · deck 02 / 04
Fall 25 Quiz 2(b)3 marks

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:

L = 2k

Here k = 10, so L = 210 = 1024 shades.

Range: 0 to L − 1 = 0 to 1023 (0 = black, 1023 = white).

Answer1024 gray levels, from 0 to 1023. General expression: L = 2k, range [0, 2k − 1].
In plain wordsEvery extra bit doubles the number of grays. 8 bits give 256, 10 bits give 1024, so the steps between neighbouring grays are 4 times finer. Fewer bits give visible bands (false contouring).

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.

Quiz 1 (D) Q1 · How to make a histogram, what it says

3 + 3 marks · deck 05
Fall 25 Quiz (set D) Q16 marks

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].

2.551011325314251627rknk
h(rk) for the slide 7 image

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.

Quiz 1 (D) Q2(a) · Four intensity types and their histograms

4 marks · deck 05
Fall 25 Quiz 1 (set D) Q2(a) · also SP23 Q2(b)4 marks

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:

7149014111263341567gray levelnk
(1) Dark image
7140112336411514697gray levelnk
(2) Bright image
102001421632044567gray levelnk
(3) Low-contrast image
365061625364655657gray levelnk
(4) High-contrast image
  1. Dark image: most pixels have low values, so the histogram is crowded on the left (dark) side. The image looks dark and details in the shadows are hidden.
  2. Bright image: most pixels have high values, so the histogram is crowded on the right side. The image looks washed out.
  3. Low-contrast image: the pixels occupy a narrow range of gray levels in the middle, so the histogram is narrow. The image looks dull and grayish.
  4. High-contrast image: the pixels cover almost the whole range, and the histogram is spread fairly evenly. The image shows a lot of gray-level detail and looks sharp.

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.

Quiz 1 (D) Q2(b) · Histogram equalization from counts

10 marks · deck 05
Fall 25 Quiz (set D) Q2(b)10 marks

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.

rk01234567
nk23569121413

Check: Σ nk = 2 + 3 + 5 + 6 + 9 + 12 + 14 + 13 = 64.

7142031526394125146137rknk
Original histogram (nk against rk)
0.110.220.0300.0510.0820.0930.1440.1950.2260.207rkp(rk)
Normalized histogram p(rk) = nk/N

Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).

rkStep 1: nkStep 2: PDFStep 3: CDFStep 4: (L−1)·CDFStep 5: sk
020.03120.03127 × 0.0312 = 0.21880
130.04690.07817 × 0.0781 = 0.54691
250.07810.15627 × 0.1562 = 1.09381
360.09380.25007 × 0.2500 = 1.75002
490.14060.39067 × 0.3906 = 2.73443
5120.18750.57817 × 0.5781 = 4.04694
6140.21880.79697 × 0.7969 = 5.57816
7130.20311.00007 × 1.0000 = 7.00007

Mapping the new gray levels into number of pixels:

gray level rknew gray level skno. of pixels nk
002
113
215
326
439
5412
6614
7713

Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.

skpixels addedn(sk)
022
13 + 5 = 88
266
399
41212
61414
71313
714208162931245146137sknk
Equalized histogram (n against new level sk)
0123456701234567input rkoutput sk
Transformation function sk = T(rk) drawn as a staircase (slide 40 style). Empty levels keep the previous step.

Try it, step by step: Fall 25 quiz set D: counts are given, so it starts at the table.

Quiz 2 (C) Q1 · Same black/white count: same histogram?

2 + 4 marks · deck 05
Fall 25 Quiz 2 (set C) Q12 + 4 marks

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

h(rk) = nk, k = 0, 1, …, L−1

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:

h(0) = 200, h(1) = 200
1002002000 (black)2001 (white)gray levelnk
Histogram of image 1 = histogram of image 2

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.

Quiz 2 (C) Q2 · Histogram equalization of a 4×5 image

14 marks · deck 05
Fall 25 Quiz (set C) Q214 marks

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.

12470
21315
52141
76314
input image

Step 1, histogram h(rk) = nk: count the pixels at each gray level.

rk01234567
nk16323212

Check: Σ nk = 1 + 6 + 3 + 2 + 3 + 2 + 1 + 2 = 20.

361061322334251627rknk
Original histogram (nk against rk)
0.150.300.0500.3010.1520.1030.1540.1050.0560.107rkp(rk)
Normalized histogram p(rk) = nk/N

Steps 2–5. PDF p(rk) = nk/N; CDF = running sum of the PDF; multiply by (L − 1) = 7; round off (.5 goes up).

rkStep 1: nkStep 2: PDFStep 3: CDFStep 4: (L−1)·CDFStep 5: sk
010.05000.05007 × 0.0500 = 0.35000
160.30000.35007 × 0.3500 = 2.45002
230.15000.50007 × 0.5000 = 3.50004
320.10000.60007 × 0.6000 = 4.20004
430.15000.75007 × 0.7500 = 5.25005
520.10000.85007 × 0.8500 = 5.95006
610.05000.90007 × 0.9000 = 6.30006
720.10001.00007 × 1.0000 = 7.00007

Mapping the new gray levels into number of pixels:

gray level rknew gray level skno. of pixels nk
001
126
243
342
453
562
661
772

Equalized histogram: add the nk that land on the same sk. Levels not listed get 0 pixels.

skpixels addedn(sk)
011
266
43 + 2 = 55
533
62 + 1 = 33
722
3610162354353627sknk
Equalized histogram (n against new level sk)
0123456701234567input rkoutput sk
Transformation function sk = T(rk) drawn as a staircase (slide 40 style). Empty levels keep the previous step.

Equalized output image: replace every pixel r by its s.

12470
21315
52141
76314
input
24570
42426
64252
76425
equalized output

Try it, step by step: Fall 25 quiz set C, every step.

Quiz 3 (D) Q1 · Two approaches of segmentation, and why LoG

4 + 2 marks · deck 08
Fall 25 Quiz 3 (set D) Q14 + 2 marks

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):

  1. Discontinuity: partition the image where the intensity changes abruptly. Methods: point, line and edge detection (gradient/Sobel, LoG, Canny).
  2. Similarity: partition the image into regions that are alike by a predefined rule. Methods: thresholding, region growing, region splitting and merging.

Why Gaussian + Laplacian (LoG).

  • The Laplacian is a 2nd derivative, so it is very sensitive to noise: every noisy pixel gives a strong response and false zero crossings.
  • Gaussian smoothing first removes the noise, so the zero crossings of the Laplacian then mark real edges only.
  • Both are linear, so they combine into one LoG mask ∇²G (cheaper), and its zero crossings give thin, well-localised edges.

Small proof (a noisy step, 2nd derivative f(x+1) + f(x−1) − 2f(x)):

signal2nd derivativezero crossings
noisy10 13 9 12 10 11 40 38 41 39 42 40-7 7 -5 3 28 -31 5 -5 5 -58
smoothed [1 2 1]/410 11 11 11 11 18 32 39 40 40 41 40-1 0 0 7 7 -7 -6 -1 1 -23

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.

Quiz 3 (D) Q2 · Chain code: start point and rotation invariant

7 + 7 marks · deck 10
F25 Quiz (Q3D) Q27 + 7 marks

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).

0123401234565576711233
boundary with each move's code · ringed = start
01234567
8-direction code: 0 = right, counting counterclockwise, 45° apart
movefrom → todirectioncode
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
CC = 5576711233  (10 moves)

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 15576711233
from 25767112335
from 37671123355
from 46711233557
from 57112335576
from 61123355767
from 71233557671
from 82335576711
from 93355767112
from 103557671123
all circular shifts of the CC · highlighted = smallest
AnswerStart-point invariant chain code = 1123355767 (smallest shift, starting at digit 6).

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.

i12345678910
this ci5576711233
next ci+15767112335
next − this02-11-601102
mod 8 = CFD0271201102
first difference, last column wraps round (next of the last digit = the first digit)
CFD = 0271201102

Step 4 · normalise (NCFD). Smallest circular shift of the CFD. This removes the start point too.

from 10271201102
from 22712011020
from 37120110202
from 41201102027
from 52011020271
from 60110202712
from 71102027120
from 81020271201
from 90202712011
from 102027120110
all circular shifts of the CFD · highlighted = smallest
AnswerChain code invariant to start point and rotation (NCFD, shape number of slides 21–22) = 0110202712.

Try it, step by step: F25 quiz boundary. Set “Normalise” to CC for part (i), CFD for part (ii).

TrapPart (i) = shape number of the chain code itself (start at the smallest rotation). Part (ii) = first difference (CFD) first, then its shape number (NCFD). Use the CFD/NCFD trick from the chain-code trainer.

Quiz 4 (C) Q1 · Dilation and erosion: size and shape

3 marks · deck 11
SP24 Q1(c) · SP22 Q4(a) · Fall 25 quiz (set C) Q13–5 marks

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.

Quiz 4 (C) Q2 · Edge detection with morphology

7 marks · deck 11
Fall 25 quiz (set C) Q27 marks

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.

000000
011110
011110
011110
011110
000000
A
111
111
111
B

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.

000000
000000
001100
001100
000000
000000
A ⊖ B
000000
011110
010010
010010
011110
000000
β(A) = A − (A ⊖ B)

Alternative (outer edge): (A ⊕ B) − A, dilation then subtraction, gives the ring just outside the square:

111111
111111
111111
111111
111111
111111
A ⊕ B
111111
100001
100001
100001
100001
111111
(A ⊕ B) − A

Try it, step by step: both edge algorithms: erode then subtract, or dilate then subtract.