CSE 4227 · Chapters 1–2 · Decks 01–02

Introduction and digital image fundamentals

What a digital image is, sampling and quantization with a real graph, bits/levels/size arithmetic, image types, and nearest-neighbour zooming with a step-by-step simulator. Fall 2024 is left out.

★ Must study on this page

Deck 01 in five minutes: what a digital image is

slides 01: 3–16Know in 2 lines
In plain wordsA photo, for a computer, is a grid of numbers. Each little square (pixel) holds how bright it is (or its colour). Digital image processing is doing maths on that grid.

Slides 3–9. An image is a two-dimensional light-intensity function f(x, y): x and y are spatial coordinates, and the value (amplitude) of f at a point is its intensity or gray level. When x, y and the amplitude are all finite, discrete quantities, the image is a digital image. A pixel is the smallest element of a digital image; each pixel has an intensity (gray level in a gray image, an R, G, B vector in a colour image). Formats: JPEG, PNG, BMP, TIFF, GIF. f(x,y) for photos, f(x,y,z) for 3-D (CT), f(x,y,t) for movies.

Slides 11–13. Why process images: enhance visual quality, restore degraded images, compress for storage/transmission, analyse for recognition. Elements of a DIP system: acquisition, storage, processing, display. Levels: low (image in → image out), mid (image in → measurements/attributes out), high (attributes in → description/understanding out).

Slides 15–16. Key stages of DIP (start from the problem domain):

stageone line
image acquisitioncapture the image with a sensor (camera, scanner); may include preprocessing such as scaling
image enhancementimprove visual quality (brightness, contrast) for a specific application
image restorationrepair degraded images (noise, blur)
morphological processingmanipulate shapes with set operations (erosion, dilation, opening, closing)
segmentationsplit the image into regions (objects / background)
representation & descriptionturn regions into a form for computers (boundary or region) and describe them
object recognitionlabel objects by shape, texture and other features
compressionreduce storage and transmission size while keeping quality
colour image processingwork with colour models, conversions and corrections

Sampling and quantization

Must studyslides 02: 12–16Came in past papers
In plain wordsA real scene is continuous: any position, any brightness. To store it, cut it twice. Sampling chooses a grid of positions (how many pixels). Quantization rounds each brightness to one of a few allowed levels (how many gray levels).

Slide 12. Computers use a discrete form of pictures; transforming the continuous analog image into a discrete approximation is digitization, in two steps: sampling and quantization.

stepdigitizesdecides
samplingthe coordinate values (x, y)the spatial resolution M × N (number of pixels)
quantizationthe amplitude (intensity) valuesthe number of gray levels L (usually a power of 2)
AB01234567sampling: one dot per sample positionquantized level (3 bits)continuous intensity along A–B
slide 15: sampling picks the positions (dots on the x-axis), quantization rounds each value to one of 2³ = 8 levels: A 7 7 7 1 2 3 4 4 5 5 5 5 5 4 3 3 2 1 0 0 7 7 7 B

Slides 16–19. A digital image is always only an approximation of the scene. It is stored as an M × N matrix with the origin (0,0) at the top-left, x down the rows and y across the columns (MATLAB numbers from 1 instead).

SP22 Final Q3(a)3 + 2 marks

(i) Mention two techniques that made the digital representation of the analog world possible. (ii) “The more intensity levels used, the finer the level of detail discernible in an image.” Explain why.

(i) Sampling: measuring the continuous scene only at a grid of points, which digitizes the coordinates and fixes the spatial resolution M × N. Quantization: rounding each sampled brightness to one of L discrete levels (L = 2k), which digitizes the amplitude. Together they turn the analog picture into a matrix of integers.

(ii) With more levels the step between neighbouring gray values is smaller, so small brightness differences (soft shading, fine texture) get different numbers and stay visible. With few levels, many different intensities are rounded to the same value; smooth areas turn into flat bands with visible jumps between them (false contouring, slides 30–34), and fine detail is lost.

Gray levels, bits and image size

Must studyslides 02: 20–25Came in past papers
L = 2k (k = bit depth)    gray range = [0, L − 1]    image size b = M × N × k bits (square: N² k)

Slide 20. f(x,y) = i(x,y) · r(x,y), with illumination 0 < i < ∞ and reflectance 0 < r < 1. The gray level l = f(x,y) lies in [Lmin, Lmax] (the grayscale): a scalar measure of intensity from black through grays to white.

Slides 21–22. Intensity (gray-level) resolution = the number of intensity levels L used. It is usually given as bits per pixel: k bits give L = 2k levels; 8 bits give 256 levels, range [0, 255].

bits klevels L = 2krange
120 – 1
240 – 3
380 – 7
4160 – 15
5320 – 31
6640 – 63
71280 – 127
82560 – 255
95120 – 511
101,0240 – 1,023
1665,5360 – 65,535

Slide 23. Spatial resolution = M × N (rows × columns). A 2048 × 1536 image has 3,145,728 pixels, a 3.1-megapixel image.

Slide 25 · answer the questionsworked

Q1 1 bit → 21 = 2 levels (0, 1). Q2 2 bits → 4 levels. Q3 p bits → 2p levels. Q4 256 intensities → log2 256 = 8 bits.

Q5 3-bit 5×5 image: gray-level resolution L = 2³ = 8 levels (range 0–7); spatial resolution 5 × 5 = 25 pixels; size b = 5 × 5 × 3 = 75 bits; bit depth 3.

F25 Quiz Q1C Q2(b)3 marks

How many shades of gray are possible in a 10-bit grayscale image? Show their numeric range. Illustrate the expression of intensity resolution.

L = 2k = 210 = 1024 shades; range [0, L − 1] = [0, 1023]. Intensity resolution of a k-bit image is L = 2k levels: more bits → more levels → finer steps between grays, less false contouring.

F22 Final B4(b) · F21 Final A3(b) (other examiners' papers)5 · 6 marks

F22: define sampling and quantization; bits for 512 intensities; spatial resolution and bit size of a 7×5 image. F21: a 256×256 image with 64 gray levels: bit depth and size in bytes; Mach band effect; index image; why more levels show finer detail.

F22: sampling digitizes coordinates, quantization digitizes amplitude. 512 intensities → k = log2 512 = 9 bits. A 7×5 image has spatial resolution 7 × 5 = 35 pixels; with 9 bits per pixel, b = 7 × 5 × 9 = 315 bits.

F21: 64 levels → k = log2 64 = 6 bits; b = 256 × 256 × 6 = 393,216 bits = 393,216 / 8 = 49,152 bytes (48 KB). Mach band effect: at the boundary between two flat bands of different brightness the eye sees a darker strip on the dark side and a brighter strip on the light side (overshoot/undershoot) that is not in the image. Index image: each pixel stores an index into a colour table (palette) holding the actual RGB values. The last part is the same as SP22 (ii) above.

Types of digital image

slides 02: 38–42Know in 2 lines
typeeach pixel holdsexample
intensity / gray (monochrome)one value: light intensity, a gray level[10 10 16 28; 9 6 26 37; …]
colour / RGBa vector of three values (red, green, blue)[99, 65, 10]
binary (black and white)one bit: 1 = white, 0 = black[0 0 0 0; 1 1 1 1]
indexan index number pointing to a colour in a colour tablepixel 4 → table row 4 = (0.5, 0.5, 0.5)

Slide 37. Choosing size and depth: for images of the same size, a low-detail image may need more pixel depth; as image size grows, fewer gray levels may be needed.

Zooming: pixel replication and nearest-neighbour interpolation

slides 02: 43–56Came in past papers
In plain wordsZooming needs more pixels than you have. Pixel replication just copies each pixel (works only for whole-number factors like ×2). Nearest-neighbour interpolation works for any size: for every new pixel, work out which old pixel it falls on, and copy that one.

Slides 43–45. Pixel replication: to double the size, duplicate each row, then each column (any integer factor works the same way). New pixels are exact copies of old ones.

32
41
original 2×2
32
32
41
41
after row duplication
3322
3322
4411
4411
after column duplication: 4×4

Slides 46–48. Interpolation uses known data to estimate unknown values (zooming, shrinking, rotating, geometric correction). Types: nearest neighbour, bilinear, bicubic. Nearest neighbour: mapping (find each target pixel's location in the source), selection (take the source pixel closest to it), assignment (copy its value): fast, but blocky “stair-step” edges.

Slides 49–54 · 3×3 → 6×6worked

Step 1 · ratios: Ratiorow = 3/6, Ratiocol = 3/6.

Step 2 · positions = ratio × [1 … 6], rounded up (ceil):

rows: 3/6 × [1 2 3 4 5 6] = [0.5 1 1.5 2 2.5 3] → ceil → [1 1 2 2 3 3]
cols: 3/6 × [1 2 3 4 5 6] = [0.5 1 1.5 2 2.5 3] → ceil → [1 1 2 2 3 3]

Step 3 · copy: output pixel (i, j) = old pixel (row position i, column position j).

10422
2187
91425
original 3×3
1010442222
1010442222
22181877
22181877
9914142525
9914142525
output 6×6

Try it, step by step: the slide example. Change the new size (e.g. 5×5, 7×7, 9×9) to see how the positions change; the class-work matrices are solved just below.

Slide 52. Rounding choice matters: for 4 → 7 the positions are floor [0 1 1 2 2 3 4], ceil [1 2 2 3 3 4 4], round [1 1 2 2 3 3 4]. The slides use ceil (1-indexed).

Slide 55 · class worksolved

2×2 → 5×5

Step 1 · ratios: Ratiorow = 2/5, Ratiocol = 2/5.

Step 2 · positions = ratio × [1 … 5], rounded up (ceil):

rows: 2/5 × [1 2 3 4 5] = [0.4 0.8 1.2 1.6 2] → ceil → [1 1 2 2 2]
cols: 2/5 × [1 2 3 4 5] = [0.4 0.8 1.2 1.6 2] → ceil → [1 1 2 2 2]

Step 3 · copy: output pixel (i, j) = old pixel (row position i, column position j).

14
37
original 2×2
11444
11444
33777
33777
33777
output 5×5

3×3 → 9×9

Step 1 · ratios: Ratiorow = 3/9, Ratiocol = 3/9.

Step 2 · positions = ratio × [1 … 9], rounded up (ceil):

rows: 3/9 × [1 2 3 4 5 6 7 8 9] = [0.333 0.667 1 1.33 1.67 2 2.33 2.67 3] → ceil → [1 1 1 2 2 2 3 3 3]
cols: 3/9 × [1 2 3 4 5 6 7 8 9] = [0.333 0.667 1 1.33 1.67 2 2.33 2.67 3] → ceil → [1 1 1 2 2 2 3 3 3]

Step 3 · copy: output pixel (i, j) = old pixel (row position i, column position j).

143
723
560
original 3×3
111444333
111444333
111444333
777222333
777222333
777222333
555666000
555666000
555666000
output 9×9

4×4 → 7×7

Step 1 · ratios: Ratiorow = 4/7, Ratiocol = 4/7.

Step 2 · positions = ratio × [1 … 7], rounded up (ceil):

rows: 4/7 × [1 2 3 4 5 6 7] = [0.571 1.14 1.71 2.29 2.86 3.43 4] → ceil → [1 2 2 3 3 4 4]
cols: 4/7 × [1 2 3 4 5 6 7] = [0.571 1.14 1.71 2.29 2.86 3.43 4] → ceil → [1 2 2 3 3 4 4]

Step 3 · copy: output pixel (i, j) = old pixel (row position i, column position j).

1437
2345
2643
4710
original 4×4
1443377
2334455
2334455
2664433
2664433
4771100
4771100
output 7×7

Slide 56. Shrinking (down-scaling) works the same way, but instead of replicating, delete every second row and column (halving). Slides 57–61 (skip): bilinear interpolation takes a distance-weighted average of the 2×2 known neighbours (smoother than nearest neighbour); bicubic uses 4×4.

Traps and one-minute sheet

slides all