Digital Image Processing, Past Papers, UOS Main Campus

Digital Image Processing Past Paper 2014 – MS CS 2nd Term UOS (CS-5813)

ProgramMS CS
Term2nd
Year2014
Course codeCS-5813
AnswersSolved ✓

University of Sargodha MS Computer Science 2nd term Digital Image Processing (CS-5813) paper, 2014 exam, session 2013-15 (80 marks, 3 hours). The paper has been retyped, and solved answers are given below for all short questions and all six long questions, including contrast stretching, histogram equalisation, finding α and β, 4/8/m-paths, linear filter design, HSI conversion and compass operators. All numbers were computed in Python.

Solved answers

Q1 – Short answers (8 × 2)

i. Size of a 100 × 200 image with 100 gray levels: 100 gray levels need k = ⌈log2100⌉ = 7 bits per pixel. Size = 100 × 200 × 7 = 140,000 bits = 17,500 bytes (≈ 17.1 KB).

ii. Analog to digital image: By sampling (digitising the spatial coordinates on a grid of M × N points) and quantisation (digitising the amplitude/intensity at each sample into one of L discrete gray levels).

iii. Gray-level (intensity) resolution: The smallest discernible change in intensity, set by the number of bits per pixel: k bits give L = 2k levels (8 bits → 256 levels). Too few levels cause false contouring.

iv. Nearest-neighbour and bilinear interpolation: Used in zooming/rotation. Nearest neighbour assigns to a new location the value of the closest original pixel (fast but blocky). Bilinear uses the 4 nearest neighbours: v(x, y) = ax + by + cxy + d, giving smoother results.

v. Linear vs non-linear operations: An operator H is linear if H[a f1 + b f2] = a H[f1] + b H[f2] (additivity and homogeneity), e.g. sum, averaging filter. Otherwise it is non-linear, e.g. max or median: max{f1 + f2} ≠ max{f1} + max{f2} in general.

vi. Cones and rods: Cones (6–7 million, concentrated in the fovea) are sensitive to colour and give fine detail in bright light (photopic vision). Rods (75–150 million, spread over the retina) give an overall picture, are sensitive to low light and not to colour (scotopic vision).

vii. Power-law (gamma) operator: s = c rγ. γ < 1 expands dark values (brightens the image), γ > 1 compresses dark values (darkens it); used for gamma correction of displays and contrast enhancement.

viii. RGB to CMY: With values normalised to [0, 1]: C = 1 − R, M = 1 − G, Y = 1 − B (for 8-bit values, C = 255 − R, etc.).

Q2 – Contrast stretching and histogram equalisation

(a) Full-scale contrast stretch (5-bit, L = 32): rmin = 9, rmax = 14, so s = round[(r − 9) × 31 / (14 − 9)] = round[6.2 (r − 9)].

r910121314
s06192531
Resulting image:
61960
19191931
252560
31192519

(b) Histogram equalisation (treated as 4-bit, L = 16, 16 pixels): sk = round[15 × Σ nj/16].

rknkp(rk)CDF15 × CDFsk
920.1250.1251.8752
1030.18750.31254.6885
1260.3750.687510.3110
1330.18750.87513.1313
1420.1251.00015.0015
Equalised image:
51052
10101015
131352
15101310

(c) Histograms: original – counts 2, 3, 6, 3, 2 at levels 9, 10, 12, 13, 14 (crowded in a narrow band 9–14). Equalised – the same counts 2, 3, 6, 3, 2 now at levels 2, 5, 10, 13, 15, spread over almost the full range 0–15, so contrast is higher. (Bar heights are unchanged because discrete equalisation only moves levels.)

Q3 – Finding α and β

From the known pixel pairs: r = 3 → s = 5 and r = 15 → s = 11 (also r = 3 → s = 5 at the bottom-right).

α·log2(4) + β = 5   →  2α + β = 5
α·log2(16) + β = 11 →  4α + β = 11
Subtract: 2α = 6  →  α = 3,  β = −1      so  s = 3·log2(1 + r) − 1

(b) Output “?” corresponds to input r = 1: s = 3 log22 − 1 = 2.

(c) Input “?” gives output 8: 3 log2(1 + r) − 1 = 8 → log2(1 + r) = 3 → 1 + r = 8 → r = 7.

Q4 – Shortest paths and 1-D derivatives

(a) V = {0, 1}; p is the bottom-left pixel (value 1), q the top-right pixel (value 1). Label rows 0 (top) to 3 (bottom).

  • 4-path: does not exist. Starting from p and moving only up/down/left/right through pixels with values 0 or 1, we can reach (3,1), (3,2), (2,2), (2,3), (1,2), (1,1), (0,1) and (2,0), but never q: q’s only 4-neighbours, (0,2) and (1,3), both have value 2, which is not in V, so q is 4-isolated.
  • 8-path: length 4, e.g. (3,0) → (2,0) → (1,1) → (1,2) → (0,3).
  • m-path: length 4, the same path. Each diagonal step is allowed under m-adjacency because the shared 4-neighbours are not in V: for (2,0)→(1,1) they are (1,0) = 2 and (2,1) = 2; for (1,2)→(0,3) they are (0,2) = 2 and (1,3) = 2.

(Lengths found by breadth-first search in Python.)

(b) Using the first derivative ∂f/∂x = f(x + 1) − f(x) and the second derivative ∂²f/∂x² = f(x + 1) + f(x − 1) − 2f(x):

Signal f555990055815
Gradient0040-90503-740
Laplacian–04-4-995-53-1011-4
Signal f56865313455
Gradient12-2-1-2-22110–
Laplacian11-41-104-10-1–

Observations: the gradient is zero in flat regions, has a single spike at each step edge (+4 at 5→9, −9 at 9→0, +5 at 0→5) and is non-zero along ramps. The Laplacian gives a double response with a zero crossing at each step (+4/−4, −9/+9, +5/−5), a strong response at the isolated point/thin line (8 between 5 and 1 → −10, then +11), and is small along the smooth sinusoidal part.

Q5 – Linear filtering (zero padding)

Filters are applied by correlation with zero padding (the masks are symmetric, so convolution gives the same result).

(a) Filtered Image 1 = ½ (pixel above + pixel below):
5432
10864
8642
4321
(b) Filtered Image 3 = ½ (above + below − left − right + 2·centre):
12434
16865
13642
8320
(c) Filtered Image 3 − Filtered Image 1 =
7002
6001
5000
400-1
= Filtered Image 2. Because the filters are linear and shift-invariant, Filter 2 = Filter 3 − Filter 1:
000
-12-1
000
× ½, i.e. the horizontal second-difference (Laplacian-type) filter ½[−1 2 −1]. Check: top-left pixel = ½(2·12 − 10 − 0) = 7 ✓. (All three images computed with NumPy.)

Q6 – HSI colour model

(a) HSI describes colour the way humans do: Hue (dominant colour, an angle 0°–360°), Saturation (purity – how much white is mixed in) and Intensity (brightness). It decouples intensity from colour information, so image-processing algorithms (e.g. histogram equalisation on I only) can be applied without distorting colours. It is drawn as a double cone/triangle with I on the vertical axis.

RGB → HSI  (R, G, B normalised to [0,1])
θ = cos⁻¹{ ½[(R−G) + (R−B)] / √[(R−G)² + (R−B)(G−B)] }
H = θ if B ≤ G,   H = 360° − θ if B > G
S = 1 − 3·min(R, G, B) / (R + G + B)
I = (R + G + B) / 3

HSI → RGB
RG sector (0° ≤ H < 120°):  B = I(1 − S),  R = I[1 + S cos H / cos(60° − H)],  G = 3I − (R + B)
GB sector (120° ≤ H < 240°): H = H − 120°;  R = I(1 − S),  G = I[1 + S cos H / cos(60° − H)],  B = 3I − (R + G)
BR sector (240° ≤ H ≤ 360°): H = H − 240°;  G = I(1 − S),  B = I[1 + S cos H / cos(60° − H)],  R = 3I − (G + B)

(b) A gray shade has R = G = B, and each component has 28 values, so there are 256 different shades of gray (out of 224 ≈ 16.7 million colours).

Q7 – Compression and compass gradient operators

Lossless compressionLossy compression
Original data recovered exactly after decompressionSome information is permanently discarded; only an approximation is recovered
Lower compression ratio (≈ 2:1 – 3:1)Much higher compression ratio (10:1 – 50:1 or more)
Removes coding and inter-pixel redundancyAlso removes psycho-visual redundancy (details the eye does not notice)
Huffman, LZW, run-length, PNG, GIFJPEG, transform coding with quantisation, MPEG
Used for medical images, text, archivesUsed for photos, video, web images

(b) Compass gradient operators (Prewitt-type, coefficients 0, ±1). Each mask responds most strongly when intensity increases in its named direction; the edge it detects is perpendicular to that direction:

E
-101
-101
-101
NE
011
-101
-1-10
N
111
000
-1-1-1
NW
110
10-1
0-1-1
W
10-1
10-1
10-1
SW
0-1-1
10-1
110
S
-1-1-1
000
111
SE
-1-10
-101
011

E/W masks detect vertical edges (gradient horizontal), N/S masks detect horizontal edges (gradient vertical), NE/SW detect edges along the NW–SE diagonal and NW/SE detect edges along the NE–SW diagonal. Each mask is the previous one rotated by 45°, and the mask with the largest response gives the edge direction at that pixel.

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.