Part 1: Gray-Level (Intensity) Transformations
1. Mathematical Concept & Mapping Function (Slides 2–3)
An intensity transformation is a point-processing operation mapping an input intensity to an output intensity via a transformation function :
- For an 8-bit image, (or normalized to ).
- Thresholding Function (Slide 2): where is the threshold value. A smooth, continuous sigmoidal curve can also be used to smoothly expand contrast around without harsh binary clipping.
2. Negative Transformation (Slides 4–5)
For an 8-bit image ():
Input (r) Output (s = 255 - r)
0 (Black) ------> 255 (White)
128 ------> 127
255 (White) ------> 0 (Black)
Purpose & Example
- Medical Imaging (Slide 4): In digital mammograms or chest X-rays, subtle lesions and microcalcifications surrounded by large dark areas are difficult for the human eye to discern. Inverting the image to a bright background with dark anomalies leverages human visual sensitivity to dark features on light backgrounds.
- Histogram Effect (Slide 5): The histogram is mirrored horizontally: a distribution skewed toward the dark end () flips entirely to the bright end ().
3. Logarithmic Transformation (Slides 6–7)
Why the Log Transformation is Used
- Dynamic Range Compression: It maps a narrow range of dark input levels into a wider range of output levels, while compressing high input values.
- Fourier Spectrum Display (Slides 6–7): The 2D Discrete Fourier Transform (DFT) of an image has a central 0-frequency DC peak that can reach values of to , while high-frequency details may have values of order to . Displaying linearly yields a single white pixel at the center surrounded by total blackness. Applying compresses this huge dynamic range into visible bands, rendering the surrounding diffraction patterns visible.
4. Power-Law (Gamma) Transformation & Gamma Correction (Slides 8–11)
Curve Behavior:
• γ < 1 (nth root): Curves upward. Expands dark values (brightens dark images).
• γ = 1: Identity line (s = c · r).
• γ > 1 (nth power): Curves downward. Compresses dark values (darkens bright images).
Physical Display Gamma Correction (Slides 10–11)
Cathode Ray Tubes (CRTs) and modern monitor controllers exhibit a physical power-law response between input voltage and emitted luminance :
If an uncorrected image is displayed, the monitor will darken all mid-tones and shadow details. To cancel this distortion, image acquisition systems apply a gamma correction: When displayed, the combined system transfer function becomes linear:
5. Walkthrough of Exercise 1 (Slides 12–15)
Question 1: Explain why we need to add 1 in the log function as .
- Mathematical Reason: For digital images, minimum intensity is (black). Since , evaluating at 0 is undefined and causes a mathematical singularity.
- Adding 1 shifts the input: when , . This ensures the output passes through the origin , mapping pure black to pure black.
Question 2: Determine coefficient in the log transformation for 8-bit images ().
We require that maximum input maps to maximum output :
Question 3: Determine coefficient in the power-law transformation for 8-bit images.
Equation: . We require that yields : (Note: If input is normalized to , then .)
Question 4: Compare natural logarithm () with base-10 logarithm (). Is there any difference in the resulting images?
- Mathematical Derivation (Slide 14): Using the change-of-base formula :
- Conclusion: There is no difference whatsoever. The change-of-base factor cancels out entirely in the scaling coefficient .
Question 5: Small image with 3-bit gray levels ().
Histogram: for . Total pixels .
Step 1: Find the scaling coefficient
For 3-bit: , . Thus, the transformation formula is:
Step 2: Compute mapped intensity values for each
(Using base-2 for clarity since , so and ):
Step 3: Accumulate pixel counts into the new histogram
| Output Level | Mapped from Input | Pixel Count Calculation | Final Count in New Histogram |
|---|---|---|---|
| 0 | 1 | ||
| 1 | None | 0 | 0 |
| 2 | 4 | ||
| 3 | None | 0 | 0 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 1 | ||
| 7 | 1 |
- Effect Observed (Slide 15): The low input levels () are stretched apart (), increasing local dark contrast. Higher input levels ( and ) are merged/compressed into single output bins ( and ).
6. MATLAB imadjust Syntax and Mechanics (Slides 16–18)
output = imadjust(img, [low_in high_in], [low_out high_out], gamma);All parameters are normalized to the range .
- Any input is clipped to .
- Any input is clipped to .
- Within , the mapping follows:
Walkthrough of Exercise 2 (Slides 17–18)
Question 1: An 8-bit image has intensities varying from 50 to 200 and appears too bright. Set parameters to to improve quality:
output = imadjust(img, [p1 p2], [p3 p4], p5);- Input Range : We stretch the active data window to the full display range:
- Output Range : Expand to the full black-to-white dynamic range :
- Gamma parameter : The image is too bright, so we must darken it. A darkening power-law curve requires:
Question 2: Find output for input when , , , , and .
Since , the function is a straight line between and .
- Normalize input to :
- Equation of the line:
- Evaluate inside brackets (Slide 18 handwritten steps): Dividing by :
- Denormalize back to 8-bit integer:
Part 2: Histogram Equalization (HE)
1. Mathematical Formulation (Slides 19–21)
Given an image with total pixels and gray levels ( for ):
- Probability of occurrence (PDF):
- Cumulative Distribution Function (CDF):
- Discrete Mapping Function:
2. Walkthrough of Exercise 3 (Slides 22–23)
- Image Specifications: Size pixels.
- Bit-depth: 3-bit levels ( to ). Factor .
- Original Histogram:
Detailed Calculation Table:
| Level | Intensity | Count | Cumulative Count | Exact Mapping: | Integer Output | |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | ||
| 1 | 1 | 0 | 0 | 0 | ||
| 2 | 2 | 1 | 1 | 0 | ||
| 3 | 3 | 2 | 3 | 1 | ||
| 4 | 4 | 4 | 7 | 3 | ||
| 5 | 5 | 6 | 13 | 6 | ||
| 6 | 6 | 3 | 16 | 7 | ||
| 7 | 7 | 0 | 16 | 7 |
Step (1): Cumulative Histogram Plot (Slide 23)
The cumulative sums plotted against are:
Step (2): New Histogram After Equalization
We place the original pixel counts into their mapped bins :
- : receives counts from
- : receives counts from
- : receives no allocations
- : receives counts from
- : receives no allocations
- : receives no allocations
- : receives counts from
- : receives counts from
Original Histogram: Equalized Histogram:
6 | * 6 | *
5 | * 5 | *
4 | * * 4 | * *
3 | * * * 3 | * * *
2 | * * * * 2 | * * * *
1 | * * * * * 1 | * * * * *
+---------------- +--------------------------
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
(Narrowly clustered: 2 to 6) (Spread across full dynamic range: 0 to 7)
Part 3: Image Contrast Metrics & Statistical Measures
1. Root-Mean-Square (RMS) Contrast (Slides 26–27)
RMS contrast is the standard deviation of pixel intensities: Where the mean intensity is .
Two Equivalent Computational Formulas (Slide 27):
- Formula 1 (Direct Definition):
- Formula 2 (Computational Shortcut via Expected Values): Substituting : Dividing through by :
2. Walkthrough of Review Quiz 1 (Slide 30)
Problem: Find the RMS contrast of the image:
Solution Method 1:
- Mean ():
- Deviations squared:
- Variance ():
- RMS Contrast:
Solution Method 2:
- Sum of squares:
- Average of squares:
- Square of the mean:
- Variance & RMS Contrast:
3. Walkthrough of Review Quiz 2 (Slide 31)
Problem: Given the pixel array , find and interpret the statistics.
Part A: Numerical Variance
- Mean ():
- Using Method 1:
- Using Method 2:
Part B: Physical & Statistical Interpretations (Slide 31)
- Arithmetic Mean (): Represents the Center of Gravity (Balance Point) of the histogram:
- Median (): Represents the Histogram Splitter (divides the cumulative area under the histogram exactly in half: to the left, to the right).
- Mode (): Represents the Highest Peak (the most frequently occurring intensity level).
4. Michelson Contrast vs. RMS Contrast (Slide 28–29)
Michelson Contrast Formula:
Detailed Comparison on the Slide 28–29 Distributions:
- (Before Equalization):
- Active range: .
- (After Equalization):
- Active range: .
- Result: Histogram equalization doubled the Michelson contrast from to and more than doubled the RMS contrast from to .
Part 4: Image Quality Metrics (RMSE, PSNR)
1. Definitions & Formulas (Slides 32–35)
For a reference image and a degraded image of size : For 8-bit images, .
Perceived Quality Rule-of-Thumb Table (Slide 35):
| PSNR (dB) | Perceived Visual Quality | Interpretation |
|---|---|---|
| Excellent | Differences are virtually imperceptible. | |
| Good | Slight differences, generally acceptable. | |
| Fair | Noticeable degradation. | |
| Poor | Severe distortion, unacceptable quality. |
Maximum Theoretical PSNR for Smallest Non-Zero Error ():
- 8-bit:
- 10-bit:
- 12-bit:
- 16-bit:
2. Walkthrough of Review Quiz 3 (Slide 34)
Problem: Compare original image with test image :
- Pixel Differences squared:
- MSE and RMSE:
- PSNR Calculation: _(Using MSE formulation yields the same result: ).*
3. Walkthrough of Exercise 4 (Slides 36–37)
Setup: Reference image is with background and center pixel : Compare against Noisy Image :
- Compute squared differences matrix :
- Row sums (Slide 37 handwritten notes):
- Row 1:
- Row 2:
- Row 3:
- Total sum:
- MSE and RMSE:
- PSNR:
Part 5: Pattern Matching & Distance Metrics
PATTERN MATCHING METRICS
--------------------------------------------------
| | |
L1 Norm L2 Norm Correlation / Angle
SAD (Manhattan) SSD (Euclidean) ZNCC (Cosine Sim)
| | |
Zero-Mean: Zero-Mean: Inherently
ZSAD (b-invariant) ZSSD (b-invariant) Affine-Invariant (a, b)
1. SAD and SSD (Slides 39–43)
Let be a template of size , and be the candidate patch in the target image.
Sum of Absolute Differences (SAD) — Norm / Manhattan Distance:
Sum of Squared Differences (SSD) — Squared Norm / Euclidean Distance:
Geometric Interpretation of vs Equidistance Contours (Slide 42):
- distance form: produces a rotated square (diamond) contour.
- distance form: produces a perfect circle.
2. Illumination Limitations & Zero-Mean Extensions (Slides 43, 51)
Under an affine illumination change where all pixel intensities shift by gain and offset :
- Standard SAD and SSD fail completely because additive bias is accumulated across all pixels, causing large errors even for structurally identical patterns.
Zero-Mean Extensions (ZSAD & ZSSD):
By subtracting the patch mean before taking differences:
- Advantage: Both ZSAD and ZSSD are invariant to additive lighting shifts ().
- Limitation: They remain sensitive to multiplicative/contrast scale changes ().
Part 6: Zero-Mean Normalized Cross-Correlation (ZNCC)
1. Statistical & Vector Formulations (Slides 45–47)
Statistical Formula:
Vector Geometry (Exercise 5, Slide 46):
Define centered difference vectors and : Then: Where:
- is the angle between the two vectors in -dimensional space.
Key Mathematical Bounds:
- (Perfect positive correlation; identical pattern shape up to positive affine scaling).
- (Orthogonal; zero linear relationship).
- (Perfect inverse correlation; photographic negative).
2. Walkthrough of Exercise 6 (Slides 48–50)
Given: template : Total pixels .
- Mean of :
- Centered Vector :
- For the 8 outer pixels:
- For the 1 center pixel:
- Norm of (Slide 49):
Test Image 3: (Both Multiplicative & Additive Changes)
- Mean of :
- Centered Vector :
- Outer pixels:
- Center pixel: (Notice: !)
- Norm of (Slide 49):
- Dot Product :
- Compute ZNCC:
- Key Takeaway: ZNCC is fully invariant to linear changes in illumination ( with ).
Behavior on Other Test Images from Exercise 6 (Slides 48, 50):
- (Additive shift): .
- (Multiplicative scaling): .
- (Negative/Inverted image): Here . The vector flips orientation: .
- (Structural noise - 1, 2, 3 pixels altered): Changing pixel values breaks vector alignment. For example, in , two pixels change from to , rotating vector away from , which lowers the correlation coefficient (, ).
Part 7: Structural Similarity Index (SSIM)
1. The SSIM Formula & Components (Slide 52)
Developed by Wang and Bovik (2004), SSIM matches human visual perception by measuring three separate attributes between images and :
- Luminance Comparison : Compares mean brightness ().
- Contrast Comparison : Compares intensity standard deviations ().
- Structure Comparison : Evaluates correlation after removing mean and variance ( is the correlation coefficient, matching ZNCC!).
- Stability Constants: prevent division by zero in near-flat or black regions.
2. Derivation of SSIM Terms from AM and GM (Slides 54–55)
The mathematical foundation behind both the luminance and contrast terms comes from the Ratio of Geometric Mean to Arithmetic Mean:
For two positive numbers and :
- Arithmetic Mean:
- Geometric Mean:
AM–GM Inequality Proof:
Therefore:
- if and only if .
Deriving the SSIM Terms (Slide 55):
- Let and :
- Let and :
3. Harmonic Mean (HM) and the Full Inequality (Slide 57)
- Harmonic Mean Definition:
- Physical Example (Slide 57): Average speed over a round-trip route of distance out at speed and return at speed :
- Connection to GM and AM: Because , it directly follows that:
4. Walkthrough of Exercise 7 (Slide 56)
Calculate , , and the ratio for pairs where :
| Metric: | ||||
|---|---|---|---|---|
| 10 | 0 | |||
| 9 | 1 | |||
| 8 | 2 | |||
| 7 | 3 | |||
| 6 | 4 | |||
| 5 | 5 | (Maximum) | ||
| 4 | 6 | |||
| 3 | 7 | |||
| 2 | 8 | |||
| 1 | 9 | |||
| 0 | 10 |
- Takeaway: The ratio is normalized to . It equals if and only if , and smoothly falls off toward as the discrepancy between the two values increases.
Part 8: Comparison of Matching Metrics & Real-World Challenges
1. Summary Comparison Table (Slide 44 & 51)
| Metric | Mathematical Formula | Invariant to (Additive)? | Invariant to (Multiplicative)? | Computational Cost |
|---|---|---|---|---|
| SAD () | No | No | Very Low (subtractions & additions only) | |
| SSD () | No | No | Low (subtractions & MAC operations) | |
| ZSAD | Yes | No | Low | |
| ZSSD | Yes | No | Moderate | |
| ZNCC | Yes | Yes (for ) | High (square roots & divisions per candidate window) | |
| SSIM | Partial | Partial | High (evaluates local window statistics) |
2. Seven Core Challenges in Pattern Matching (Slide 58)
- Changes of Image Intensities: Direct sunlight, shadows, or automatic camera gain alter pixel values (handled by ZNCC or ZSAD).
- Occlusion Problem: An intervening foreground obstacle covers part of the template, altering squared errors across the patch.
- Rotations of a Pattern: Standard 2D sliding templates assume axis-aligned patterns. Any rotation breaks row-column alignment.
- Scale Changes: Distance changes between camera and scene cause the target to appear larger or smaller than the fixed template size.
- Perspective Distortion: Non-frontal viewing angles introduce homographic/keystone transformations that warp square features into general quadrilaterals.
- Changes of Focus Levels: Out-of-focus blur removes the high-frequency components that cross-correlation relies upon.
- The Aperture Problem (Insufficient Gradient Directions): If a local template contains only a straight edge (a 1D gradient), motion or matches perpendicular to the gradient can be detected, but movement along the parallel edge is ambiguous and cannot be localized. Point features (corners with gradients in at least two orthogonal directions) are required for unique pattern matching.