CSS 433 Computer Vision — Comprehensive Lecture & Exercise Guide
Instructor: Prof. Toshiaki Kondo (SIIT, Thammasat University)
Topic: Review of Acquisition Optics & Chapter 2: Digital Image Fundamentals
Part 0: Review — The Camera Exposure Plane (Slide 2)
Slide 2 establishes the physical trade-offs in camera acquisition through a two-axis exposure coordinate plane:
- Vertical Axis (Aperture / F-number): Ranges from Large Aperture () at the top to Small Aperture () at the bottom.
- Horizontal Axis (Shutter Speed): Ranges from Fast Shutter () on the left to Slow Shutter () on the right.
Large Aperture (f/2)
[Shallow DOF / More Light]
^
Quadrant A | Quadrant B
(Fast & Wide) | (Slow & Wide)
| ===> BRIGHT
Fast Shutter <--------------+--------------> Slow Shutter
[Frozen Motion] | [Motion Blur]
Quadrant D | Quadrant C
(Fast & Narrow) | (Slow & Narrow)
|
v
Small Aperture (f/32)
[Deep DOF / Less Light]
Analysis of the Four Operating Quadrants:
- Quadrant A (Large Aperture + Fast Shutter):
- Optical Effect: Shallow Depth of Field (DOF) with Frozen Motion.
- Visual Characteristic: Crisp foreground subject, heavily blurred background (bokeh), and high-speed motion captured without streak artifacts.
- Quadrant B (Large Aperture + Slow Shutter):
- Optical Effect: Maximum light collection (Bright / Overexposed) with severe Motion Blur and Shallow DOF.
- Quadrant C (Small Aperture + Slow Shutter):
- Optical Effect: Deep Depth of Field (Deep DOF) with Blurred Motion.
- Visual Characteristic: Landscape photography look; both near and far objects are in focus, but moving elements (e.g., water, moving cars) are smoothed into motion trails.
- Quadrant D (Small Aperture + Fast Shutter):
- Optical Effect: Severely photon-starved (Dark / Underexposed) with Frozen Motion and Deep DOF.
Part 1: Digitization — Spatial Sampling & Quantization (Slides 3–12)
Converting a continuous real-world scene into a digital image requires two distinct discretization steps:
Continuous Image f(x, y)
│
▼ [Step 1: Spatial Sampling] ---> Discretizes Coordinates (x, y) into (r, c)
Discrete Lattice Grid
│
▼ [Step 2: Quantization] ---> Discretizes Amplitude / Brightness into L levels
Digital Matrix I[r, c]
1. Spatial Sampling (Slides 4–6, 8–11)
- Definition: Discretization of the continuous spatial spatial domain into an array of discrete grid elements (pixels or pels).
- Sensor Resolution: Determined by the physical sensor fabrication (e.g., Canon EOS 5DS: ).
- Image as a Matrix: An image is a numerical 2D array:
- A value of corresponds to pure black; represents maximum brightness (white).
- Coordinate Systems (Slide 6):
- 0-indexed: Origin is at the top-left; rows , columns (used in C/C++, Python, OpenCV).
- 1-indexed: Origin is at the top-left; rows , columns (used in MATLAB).
- Sampling Defect — Block Artifacts (Slide 11):
- When an image is subsampled to an insufficient spatial resolution (e.g., downsampled from to ), the continuous contours break into visible square pixel blocks upon display.
2. Quantization (Slides 7, 12)
- Definition: Discretization of continuous light amplitude (radiance) into a finite set of integer intensity levels.
- Hardware: Performed by an Analog-to-Digital Converter (ADC). In modern CMOS sensors, ADCs are placed on each column of the pixel array.
- Bit Depth ():
- Monochromatic (Grayscale): 8 bits () intensity levels, .
- True-Color RGB: 3 channels 8 bits = 24 bits colors.
- Quantization Defect — False Contouring (Slide 12):
- When the number of quantization levels is severely restricted (e.g., dropping from 256 levels to 16, 8, 4, or 2 levels), smooth, continuous luminance gradients degrade into distinct, step-like bands known as false contours.
Fully Worked Exercise 1: Size of a Video Sequence (Slide 13)
Problem Statement:
Let a full-color video sequence have (frames per second). A full-color image frame consists of 3 color channels (Red, Green, Blue). Each channel comprises pixels with 8-bit intensity levels.
- Find the amount of uncompressed video data generated per second in both bits/sec and Bytes/sec.
- How long can a standard single-layer DVD ( storage capacity) store this raw uncompressed video stream?
Step-by-Step Solution:
Step 1: Calculate the data rate per second.
- Number of pixels per single color channel:
- Total bits per frame across 3 channels ():
- Total data rate in bits per second:
- Total data rate in Bytes per second (dividing by ):
Step 2: Calculate storage duration on a 4.7 GB DVD.
Commercial storage media manufacturers define .
Therefore, the DVD capacity is:
Dividing total capacity by the Byte rate per second:
Converting to minutes and seconds:
(Note: If computed using binary gibibytes where , , but storage media specs universally follow the decimal standard shown in the slide’s handwritten notes).
Part 2: The Sampling Theorem, Aliasing & Slit Animation (Slides 14–24, 44–46, 47–48)
1. The Nyquist-Shannon Sampling Theorem (Slide 16)
To accurately reconstruct an analog signal of highest frequency without aliasing distortion, the sampling frequency must be at least twice the maximum signal frequency:
Where is the Nyquist frequency.
Two Engineering Solutions to Prevent Aliasing:
- Increase : Use a higher-density sensor array or higher temporal frame rate.
- Apply an Anti-Aliasing Filter: Pass the input through an optical low-pass filter (OLPF) prior to sampling to eliminate frequencies above .
Fully Worked Exercise 2: The Sampling Theorem (Slide 17)
Problem Statement:
To represent the continuous signal without aliasing: What is the minimum sampling frequency? Express it using pertinent variables from , and .
Step-by-Step Solution:
The standard mathematical form of a sinusoidal wave as a function of continuous coordinate is: Comparing this to the given expression :
- The angular frequency is .
- The cyclical frequency of the input signal is:
- According to the Nyquist criterion, the minimum sampling frequency must satisfy:
Final Answer: (Variables [amplitude], [phase angle], and [DC bias offset] affect only signal magnitude and offset; they have no bearing on frequency or required sampling rate).
2. Mathematical Prediction of Aliasing Frequencies (Slides 18, 20, 48)
When a signal exceeds the Nyquist limit (), it folds back into the baseband as an erroneous ghost frequency .
Slides 20 and 48 provide two analytical formulations to compute :
Nyquist Limit (fs/2)
|
0 | fs 2fs
+-----------------+-----------------+-----------------+-----> Frequency
| PASSBAND |
| (No Aliasing) | Folds back | Folds forward |
| |<--- (fs - r) |<--- (r) |
Method 1: The Modulo / Remainder Formulation (Slide 20, 48)
- Calculate the remainder of the input frequency with respect to the sampling rate:
- The alias frequency is the minimum distance to the nearest sampling harmonic (the smaller of and ):
Method 2: The Nearest Multiple Formulation (Slide 48)
- Find the integer multiple index nearest to the ratio:
- Calculate the folded absolute difference:
Fully Worked Exercise 3: Aliasing Errors (Slides 19–23)
Problem 1:
Given .
The Nyquist frequency is .
Predict the alias frequency for and .
- For :
- Method 1: .
. - Method 2: .
.
- Method 1: .
- For :
- Method 1: .
(appears as a constant DC flatline). - Method 2: .
.
- Method 1: .
Problem 2:
Given .
The Nyquist frequency is .
Predict for inputs :
| (Hz) | $f_{\text{aliasing}} = | f_{\text{in}} - 8n | $ | State | |||
|---|---|---|---|---|---|---|---|
| 5 | 5 | 3 | 1 | $ | 5 - 8 | = \mathbf{3\text{ Hz}}$ | Aliased |
| 6 | 6 | 2 | 1 | $ | 6 - 8 | = \mathbf{2\text{ Hz}}$ | Aliased |
| 7 | 7 | 1 | 1 | $ | 7 - 8 | = \mathbf{1\text{ Hz}}$ | Aliased |
| 8 | 0 | 8 | 1 | $ | 8 - 8 | = \mathbf{0\text{ Hz}}$ | DC Constant |
| 9 | 1 | 7 | 1 | $ | 9 - 8 | = \mathbf{1\text{ Hz}}$ | Aliased |
| 10 | 2 | 6 | 1 | $ | 10 - 8 | = \mathbf{2\text{ Hz}}$ | Aliased |
| 11 | 3 | 5 | 1 | $ | 11 - 8 | = \mathbf{3\text{ Hz}}$ | Aliased |
| 12 | 4 | 4 | 1 or 2 | $ | 12 - 8 | = \mathbf{4\text{ Hz}}$ | At Nyquist boundary |
| 13 | 5 | 3 | 2 | $ | 13 - 16 | = \mathbf{3\text{ Hz}}$ | Aliased |
| 14 | 6 | 2 | 2 | $ | 14 - 16 | = \mathbf{2\text{ Hz}}$ | Aliased |
Fully Worked Today’s Quiz: Part 1 (Slides 47–48)
Problem Statement:
Given and .
Find using both Solution (i) and Solution (ii).
Solution:
-
Solution (i) — Modulo / Remainder Method:
-
Solution (ii) — Nearest Multiple Method:
Result: Both formulations yield .
3. Slit Animation / Moiré Animation (Slides 24, 44–46)
While aliasing is typically an unwanted defect in computer vision, Moiré animation uses it systematically to generate motion illusions from static printed sheets:
- Prepare frames representing a cyclic sequence of motion (e.g., frames of a shifting square, or frames of a galloping horse).
- Interleave the frames: Construct a single composite image by interleaving vertical slices: column 1 from frame 1, column 2 from frame 2, …, column from frame , then repeating cyclically.
- Construct a sampling mask: Create an opaque physical barrier sheet with transparent vertical slits having a repetition period of columns (width of transparent slit = 1 column, opaque barrier = columns).
- Slide the mask: As the barrier translates horizontally by , it alternately unmasks frame 1, frame 2, …, frame , producing smooth motion due to spatial subsampling.
Part 3: Bit-Plane Decomposition & Run-Length Encoding (Slides 25–30, 47)
1. Bit-Plane Decomposition
Any 8-bit monochromatic image pixel can be represented as an 8-bit binary polynomial: Decomposing an image creates 8 binary matrices (Bit-planes 0 to 7):
- Bit-plane 7 (MSB, weight 128): Contains the primary structural layout, global contrast, and boundaries.
- Bit-plane 0 (LSB, weight 1): Appears as visually imperceptible random noise, making it suitable for steganography and fragile watermarking.
Fully Worked Exercise 4: Bit-Plane Decomposition (Slide 26)
Problem Statement:
Perform bit-plane decomposition on the grayscale image: What will happen to this image if the least significant bit (LSB) plane is discarded?
Step-by-Step Solution:
Step 1: Convert all matrix entries to 8-bit unsigned binary ().
- For 8:
- For 57:
- For 215: (Slide 27 shows conversions via base-8 octal: , and base-16 hex: ).
- For 120:
Step 2: Construct the 8 binary bit-plane matrices. Writing :
Step 3: Discard the LSB Plane (). Setting the LSB to 0 (or subtracting ):
The reconstructed image becomes: Conclusion: Discarding the LSB changes pixel intensities by at most unit. This change is imperceptible to the human eye.
Fully Worked Today’s Quiz: Part 2 (Slide 47)
Problem Statement:
Perform bit-plane decomposition on the matrix:
Step-by-Step Solution:
Step 1: Convert each entry to 8-bit binary.
- 212:
- 105:
- 55:
- 176:
Step 2: Construct the decomposition sum.
Matching bits for each plane:
2. Run-Length Encoding (RLE) & Compression Metrics (Slides 28–30)
Run-Length Encoding (RLE) is a lossless data compression technique that replaces consecutive repeated symbols (runs) with a single counter value.
Example from Slide 28:
Given binary sequence: Alternative valid RLE formats:
- Pair format:
- Alternating run-count format (assuming sequence starts with 0):
- Transition coordinate format: , storing the 1-based start positions and run lengths of the ones.
Detailed Breakdown of Compression Ratio Example (Slide 30):
A binary image has dimensions: After RLE, the entire image is reduced to .
- Why are 11 bits necessary for each run?
- The maximum possible length of a continuous run across a row is the full image width: .
- A 10-bit integer can only index states (values to ).
- To represent a maximum run of without ambiguity (or values in range ), the required bit allocation is:
- Original uncompressed bit count:
- Compressed code bit count:
- Compression Ratio ():
- Relative Data Redundancy (): (This indicates that of the original data was redundant).
Part 4: Digital Watermarking (Slides 31–41)
Digital watermarking embeds verification data into an image for copyright management, tampering detection, and content authentication.
1. Visible Spatial-Domain Watermarking (Slides 33–34)
Blends a visible watermark pattern over an image using a linear transparency factor :
- When , the watermark is semi-transparent ( underlying image, watermark pattern).
2. Invisible LSB Spatial-Domain Watermarking (Slides 35–39)
Hides information in the least significant bits of the carrier image.
The 2-LSB Insertion Formula (Slide 35):
This operation works as follows:
- Dividing by , taking the floor, and multiplying by clears (zeros out) the two least significant bits of :
- Dividing by and taking the floor isolates its two most significant bits () and shifts them to positions :
- The sum places the two MSBs of directly into the two vacated LSB positions of .
Extraction Formula:
To retrieve the embedded watermark :
Fragility and Compression Vulnerability (Slide 38):
Spatial LSB watermarks are fragile. When an image undergoes JPEG lossy compression, the Discrete Cosine Transform (DCT) combined with high-frequency quantization discards subtle spatial variations. The reconstructed LSBs are corrupted (RMS error ), rendering the extracted watermark illegible.
Fully Worked Exercise 5: Watermarking in 2 LSBs (Slides 36–37)
Problem Statement:
Using the equation , embed watermark into carrier image :
Step-by-Step Solution:
Step 1: Compute the modified carrier terms (zeroing the 2 LSBs).
- :
(Binary: ) - :
(Binary: ) - :
(Binary: ) - :
(Binary: )
Step 2: Compute the watermark terms (extracting the 2 MSBs).
- :
(Binary: ) - :
(Binary: ) - :
(Binary: ) - :
(Binary: )
Step 3: Sum the two components to form .
- Top-Left:
- Top-Right:
- Bottom-Left:
- Bottom-Right:
(This matches the professor’s handwritten result on Slide 37).
Fully Worked Exercise 6: Spatial-Domain Watermarking (Slide 40)
Problem Statement:
An alphabet letter is embedded into the LSB plane of the following image. Retrieve and identify the letter.
Step-by-Step Solution:
To retrieve the LSB plane, compute :
- If the pixel value is even, .
- If the pixel value is odd, .
Row-by-Row Parity Check:
- Row 1:
- Row 2:
- Row 3:
- Row 4:
- Row 5:
- Row 6:
- Row 7:
- Row 8:
Reconstructed Binary Matrix & Pattern Visualization:
Rendering as and as :
. . . . . . . .
. █ █ █ █ █ █ . <-- Horizontal bar of letter "T"
. █ █ █ █ █ █ . <-- Double-thickness horizontal bar
. . . █ █ . . . <-- Vertical stem of letter "T"
. . . █ █ . . . <-- Vertical stem
. . . █ █ . . . <-- Vertical stem
. . . █ █ . . . <-- Vertical stem
. . . . . . . .
Final Answer: The recovered letter is T.