IVP Lectures 1-15
Digital Image Processing β Detailed Speedrun Notes
The notes follow the actual sequence of the supplied NPTEL playlist and deliberately preserve the way the lecturer develops the subject. Closely related lectures are grouped conceptually, but every lecture is separately accounted for.
The official NPTEL course listing gives the first 15 lectures as:
- Introduction to Digital Image Processing
- Application of Digital Image Processing
- Image Digitalisation, Sampling, Quantization and Display
- Signal Reconstruction from Samples: Convolution Concept
- Signal Reconstruction from Image
- Quantizer Design
- Relationship between Pixels
- Relationship of Adjacency and Connected Components Labeling
- Application of Distance Measures
- Basic Transform
- Image Formation β I
- Image Formation β II
- Image Geometry β I
- Image Geometry β II
- Stereo Imaging Model β II
The course then moves to interpolation/resampling, so Lecture 15 is the end of the first camera/stereo block.
Lecture 1 β Introduction to Digital Image Processing
1. What does “Digital Image Processing” mean?
The lecturer starts by unpacking the phrase itself.
A digital image is an image represented in digital/numerical form, and digital image processing means processing such images using a digital computer.
The important distinction is that the course is not merely about manipulating photographs. An image is treated as a signal carrying information, and the computer is used to transform, analyze, or extract information from that signal.
A useful abstraction is:
$$ \text{physical scene} \rightarrow \text{image acquisition} \rightarrow \text{digital image} \rightarrow \text{processing} \rightarrow \text{information / improved image}. $$2. Why do we need image processing?
2.1 Improvement of pictorial information for human perception
The first major application is to make an image look better or become easier to interpret.
Examples of operations that fit here:
- removing noise,
- improving contrast,
- sharpening,
- removing blur,
- enhancing details.
The computer is therefore being used as a tool to improve the visual representation.
2.2 Autonomous machine applications
The second major motivation is that the image is not necessarily meant to be viewed by a human at all.
Instead, the image can be processed so that a machine can:
- detect an object,
- measure an object,
- recognize an object,
- inspect a manufactured product,
- track something,
- make a decision.
This is the connection between image processing and machine vision / computer vision.
2.3 Efficient storage and transmission
The third motivation is reducing the amount of data required to:
- store an image,
- transmit an image,
- transmit video.
This introduces the idea that an image contains redundancy and that image-processing techniques can exploit that redundancy.
This motivation eventually leads toward image compression.
3. Image-processing applications introduced
The lecture uses examples to show the breadth of the field.
Important application areas include:
Medical imaging
Examples include:
- X-ray imaging,
- CT,
- mammography,
- medical diagnosis.
The objective can be enhancement for a doctor as well as extraction of useful information.
Remote sensing
Images acquired from:
- aircraft,
- satellites,
can be processed for:
- weather analysis,
- crop assessment,
- geographical analysis,
- atmospheric studies.
Astronomy
Image processing is useful when the objects being observed are faint, noisy, or extremely far away.
Examples include:
- stars,
- galaxies,
- star formation.
Machine vision
This is particularly important for industrial automation. An imaging system can inspect objects on a production line and determine whether they satisfy specified requirements. Atuomated target detection and tracking, finger print recognition
4. Image-processing system as a pipeline
The important conceptual pipeline is:
Image acquisition
β
Preprocessing
β
Segmentation
β
Representation / description
β
Recognition / interpretation
β
Image understanding
Lecture 2 β Applications of Digital Image Processing
1. Human-oriented vs machine-oriented processing
A key distinction is:
Human perception
The output is primarily intended to be viewed.
Examples:
- contrast enhancement,
- noise removal,
- deblurring,
- visual enhancement.
Machine interpretation
The image is processed to extract a description that a computer can use. Examples:
- industrial inspection,
- automated target detection,
- tracking,
- fingerprint recognition,
- analysis of aerial/satellite imagery.
The same image-processing operation can therefore have very different objectives depending on the final consumer of the information.
2. Industrial machine vision
The lecturer discusses automation of industrial processes. A typical example is a bottling/assembly line.
The general idea is:
manufacturing process
β
camera acquires image
β
extract relevant object information
β
inspect / classify
β
accept, reject, or control process
This illustrates why machine vision is different from simply making an image visually pleasing.
The computer has to extract features/descriptions useful for a decision.
3. Other application examples
The lecture discusses applications such as:
- automated target detection and tracking,
- fingerprint recognition,
- aerial image processing,
- satellite image processing,
- weather-related analysis,
- crop assessment.
The important commonality is that the image becomes an information source.
4. The complete digital image-processing system
The lecture ends by tying the application discussion back to the processing pipeline.
The stages are:
1. Image acquisition
Capture the image.
2. Preprocessing
Correct obvious undesirable effects.
3. Segmentation
Separate the image into meaningful regions/objects.
4. Representation and description
Represent each relevant object in a compact/useful form and extract features.
5. Recognition and interpretation
Determine what the objects/features represent.
6. Knowledge base
Prior information can assist the processing stages and facilitate communication between modules.
Why this matters later
The rest of the course develops mathematical tools corresponding to different pieces of this pipeline.
Lecture 3 β Image Digitalisation, Sampling, Quantization and Display
1. Why is digitization necessary?
A physical image is fundamentally continuous.
The image can be represented as:
$$ f(x,y) $$where:
- $x,y$ are spatial coordinates,
- $f(x,y)$ is the intensity at that location.
For a real image, the intensity can vary continuously across space.
A computer, however, cannot store infinitely many spatial positions and arbitrary real-valued intensities. Therefore we need digitization.
2. Image digitization has two stages

The lecturer emphasizes two separate operations:
$$ \boxed{\text{Sampling}} \quad+\quad \boxed{\text{Quantization}} $$Sampling
Select discrete spatial positions.
Quantization
Convert the intensity measured at each selected position into one of a finite number of allowed values. This distinction should become automatic.
3. Image sampling
Suppose the continuous image is
$$ f(x,y). $$
f = reflectance between 0 to 1 times intensity between 0 to infinity.
Sampling chooses points on a spatial grid:
The resulting samples are:
$$ f[m,n]=f(m\Delta_x,n\Delta_y). $$Thus the image is converted from a continuous surface to a discrete set of spatial samples.
4. Intensity profile
The lecturer motivates the continuous nature of the image by considering a line through an image. If we select a horizontal line, the image becomes a 1-D intensity profile:
$$ g(x)=f(x,y_0). $$The intensity can take values between a minimum and maximum along that line.
The same idea applies to vertical lines or arbitrary directions. This lets the lecturer reduce the initial image problem to the familiar problem of sampling a 1-D signal.
5. Signal bandwidth
To understand how densely a signal must be sampled, we need its frequency content. For a periodic 1-D signal, Fourier series can be used.
For an aperiodic signal, the Fourier transform is used. The frequency spectrum tells us the range of frequencies present in the signal.
If the highest frequency present is $B$, the sampling theorem gives the familiar condition:
$$ \boxed{f_s\geq 2B} $$where $f_s$ is the sampling frequency.
The minimum value $2B$ is the Nyquist rate.
6. Aliasing
If:
$$ f_s < 2B, $$the signal is undersampled.
The spectral replicas generated by sampling overlap.
The resulting distortion is called aliasing.
The key conceptual picture is:
adequate sampling
spectral replicas separated
β
reconstruction possible
insufficient sampling
spectral replicas overlap
β
aliasing
Once aliasing has occurred, the original signal cannot in general be uniquely recovered from the samples.
7. Sampling a 2-D image
An image is a 2-D signal, so frequency is also 2-D.
Instead of a single frequency variable, we have spatial frequency components in two directions.
Conceptually:
$$ (\omega_x,\omega_y). $$The sampling operation therefore creates a 2-D grid of samples.
The same basic idea applies:
the spatial sampling density must be sufficiently high relative to the highest spatial frequencies in the image.
8. Quantization
After sampling, the spatial coordinates are discrete, but the measured sample value can still be continuous.
Suppose a sampled value is $x$.
A quantizer maps it to one of $L$ allowed reconstruction levels:
$$ x\rightarrow Q(x). $$Therefore:
continuous image
β
spatial sampling
β
discrete locations + continuous intensities
β
quantization
β
digital image
9. Number of bits
If there are $L$ intensity levels, the number of bits required per sample is:
$$ b=\log_2 L. $$For example, 256 gray levels require:
$$ b=\log_2(256)=8 $$bits per pixel.
For a typical RGB color image, there are three color planes:
- red,
- green,
- blue.
If each plane uses 8 bits, then:
$$ 8+8+8=24 $$bits per pixel.
10. Display
The final digital values need to be displayed in a way that humans can perceive.
The important conceptual point is that the digital representation is an intermediate numerical representation:
physical image
β
digitization
β
numbers / pixel matrix
β
processing
β
display
Lecture 4 β Signal Reconstruction from Samples: Convolution Concept
Lecture 4 temporarily steps back from images and develops the 1-D signal reconstruction machinery.
The purpose is to understand how a continuous signal can be reconstructed from its samples.
1. Representing sampling mathematically
Let the original continuous signal be:
$$ x(t). $$Sampling can be represented by multiplying $x(t)$ by a periodic impulse train, often written as a comb function.
Conceptually:
$$ x_s(t)=x(t)\operatorname{comb}(t,\Delta t). $$The impulse train selects the values of $x(t)$ at regular intervals.
2. Why Fourier analysis is useful
Sampling in the time/spatial domain has a very simple interpretation in the frequency domain. Multiplication in one domain corresponds to convolution in the other. Thus the spectral effect of sampling can be understood through the Fourier transform.
The sampled spectrum consists of repeated copies of the original spectrum. This is the frequency-domain explanation of the Nyquist condition and aliasing.
3. Convolution
The lecturer introduces convolution as an operation between two signals.
For continuous signals:
$$ y(t)=x(t)*h(t) $$with
$$ y(t)= \int_{-\infty}^{\infty} x(\tau)h(t-\tau)\,d\tau. $$Equivalently, one signal can be thought of as being:
- reversed,
- shifted,
- multiplied,
- integrated.
The important signal-processing property is:
$$ \boxed{ x(t)*h(t) \quad\longleftrightarrow\quad X(\omega)H(\omega) } $$under the Fourier transform.
So convolution in the signal domain corresponds to multiplication in the frequency domain.
4. Reconstruction idea
After sampling, we have impulses whose amplitudes are the sample values.
To reconstruct the original continuous signal, we pass the sampled signal through a suitable reconstruction/interpolation operation.
The ideal reconstruction filter has a frequency response that:
- retains the original spectral copy,
- rejects the unwanted replicated spectra.
For a band-limited signal satisfying the sampling theorem, the original signal can theoretically
be reconstructed.

Lecture 5 β Signal Reconstruction from Image
Lecture 5 transfers the reconstruction idea from 1-D signals to images.
1. Image as a 2-D signal
The continuous image is:
$$ f(x,y). $$Sampling creates:
$$ f[m,n]. $$The inverse problem is:
Given the discrete samples $f[m,n]$, how can we reconstruct a continuous image?
Unit of frequency for images - Cycles/unit length
2. Two-dimensional sampling
Instead of a 1-D impulse train, a 2-D sampling grid is used.
The sample locations form a lattice:
β’ β’ β’ β’
β’ β’ β’ β’
β’ β’ β’ β’
Each dot is a sampled image location.
3. 2-D frequency domain

DPI - X samples per inch. Its a measure of the sampling frequency
An image has spatial frequencies in both directions.
We can think of the spectrum as:
$$ F(\omega_x,\omega_y). $$Sampling produces repeated copies of the 2-D spectrum.
The separation between copies depends on the sampling frequencies in the two directions.
Therefore the sampling requirements are fundamentally 2-D versions of the 1-D sampling theorem.
4. Reconstruction
The reconstruction process attempts to isolate the original spectral region from the periodic spectral replicas.
Conceptually:
$$ \text{sampled image} \rightarrow \text{2-D reconstruction filter} \rightarrow \text{continuous image}. $$The important idea is that interpolation/reconstruction is not an arbitrary visual trick. It has a signal-processing interpretation.
5. Quantization revisited
The lecturer connects the two stages of digitization:
Sampling
$$ f(x,y)\rightarrow f[m,n] $$Quantization
$$ f[m,n]\rightarrow Q(f[m,n]). $$Only after both operations do we have a true digital image.
6. Key takeaway from Lectures 3β5
Keep the following distinction absolutely clear:
Sampling
β discretizes spatial coordinates.
Quantization
β discretizes intensity values.
Reconstruction
β attempts to recover a continuous signal/image from samples.
Aliasing
β information loss caused by insufficient sampling.
Lecture 6 β Quantizer Design
Now the lecturer focuses on the second half of digitization:
Given a finite number of intensity levels, where should the quantization levels be placed?
This is more subtle than simply dividing the intensity range uniformly.
1. Quantization model
Let:
- $u$ = input value,
- $u'$ = quantized/reconstructed value.
The quantization error is:
$$ e=u-u'. $$A good quantizer should make this error small.
2. Decision levels and reconstruction levels
A scalar quantizer divides the input range into intervals.
Each interval is represented by a reconstruction value.
Schematically:
input axis
---|---------|---------|---------|---
t1 t2 t3 t4
r1 r2 r3
Here:
- $t_k$ are transition/decision levels,
- $r_k$ are reconstruction levels.
An input falling inside a particular interval is mapped to the corresponding $r_k$.
3. Mean-square quantization error
A natural objective is:
$$ D=E[(u-u')^2]. $$For a continuous random variable with probability density $p_u(u)$, the distortion is computed by integrating the squared error weighted by the input probability density.
The design problem is therefore:
choose the decision levels and reconstruction levels that minimize mean-square error.
4. LloydβMax quantizer
The lecturer introduces the LloydβMax optimum mean-square-error quantizer.
The goal is to minimize:
$$ E[(u-u')^2] $$for a specified number of quantization levels and a specified input probability density.
The optimum conditions produce two important relationships.
4.1 Optimum reconstruction level
For a given quantization interval $[t_k,t_{k+1}]$, the optimum reconstruction value is the conditional mean:
$$ \boxed{ r_k= \frac{ \int_{t_k}^{t_{k+1}}u\,p_u(u)\,du }{ \int_{t_k}^{t_{k+1}}p_u(u)\,du } } $$Interpretation:
The reconstruction level should be the probability-weighted center of the input values that get mapped to that level.
4.2 Optimum decision level
For two neighboring reconstruction values $r_k$ and $r_{k+1}$, the optimum transition level lies midway between them:
$$ \boxed{ t_{k+1}=\frac{r_k+r_{k+1}}{2} } $$for the standard squared-error criterion.
So the LloydβMax design alternates between:
decision levels β determine reconstruction levels
β
reconstruction levels β determine decision levels
β
iterate
5. Why the equations are nonlinear
The optimum conditions depend on one another.
The transition levels determine the integration intervals, while the reconstruction levels depend on those intervals.
Thus the equations have to be solved simultaneously.
The lecturer notes that numerical methods such as Newton iteration can be used.
6. Large number of quantization levels
When the number of levels is large, the probability density can sometimes be approximated locally as piecewise constant.
This leads to simpler approximations.
The general principle remains:
allocate quantization resolution according to the statistics of the input.
7. Uniform input distribution
If the input is uniformly distributed over a range, the optimum quantizer becomes a uniform quantizer.
For a uniform density, the transition levels and reconstruction levels are equally spaced.
Let the quantization step be:
$$ q. $$Then:
$$ q=\frac{t_{L+1}-t_1}{L} $$for $L$ equal intervals.
The reconstruction level is centered within its interval:
$$ r_k=t_k+\frac q2. $$8. Quantization error for a uniform quantizer
For a uniform quantizer, the error is uniformly distributed over:
$$ -\frac q2\leq e\leq\frac q2. $$The mean-square error is:
$$ E[e^2]=\frac{q^2}{12}. $$This is an important result.
9. Relationship with number of bits
If the full input range has width $A$ and the quantizer uses $B$ bits, there are:
$$ L=2^B $$levels.
Therefore:
$$ q=\frac{A}{2^B}. $$As $B$ increases, the quantization step decreases exponentially.
Since:
$$ D=\frac{q^2}{12}, $$the quantization error decreases rapidly with the number of bits.
10. Non-uniform input distributions
The lecturer also discusses the case where the input probability density is not uniform, including distributions such as Gaussian/Laplacian-type densities.
The important lesson is:
The optimum quantizer depends on the probability distribution of the input.
If values are concentrated heavily in one region, it can be wasteful to assign the same resolution everywhere.
11. Practical issue
In many practical situations, the exact probability density of the input is not known in advance.
A uniform quantizer is therefore attractive because it is simple and does not require detailed prior statistical knowledge.
Part III β Relationships Between Pixels
Lectures 7β9
Once the image is a matrix of numbers, we need a language for describing the spatial relationship between its elements.
This block develops:
- neighborhoods,
- adjacency,
- connectivity,
- connected components,
- distance,
- image operations.
Lecture 7 β Relationship Between Pixels
1. Digital image as a matrix
A digital image can be represented as:
$$ f(x,y) $$where $x,y$ are now discrete coordinates.
Each matrix element is a pixel.
The lecturer asks:
How are these pixels related to one another?
2. Neighborhood
For a pixel:
$$ p=(x,y), $$its immediate spatial neighbors can be defined in different ways.
2.1 4-neighborhood
The four horizontally/vertically adjacent pixels are:
$$ N_4(p)= \{(x-1,y),(x+1,y),(x,y-1),(x,y+1)\}. $$2.2 Diagonal neighborhood
The four diagonal pixels are:
$$ N_D(p)= \{(x-1,y-1),(x-1,y+1),(x+1,y-1),(x+1,y+1)\}. $$2.3 8-neighborhood
The full surrounding neighborhood is:
$$ N_8(p)=N_4(p)\cup N_D(p). $$It contains up to eight surrounding pixels.
3. Adjacency
Neighborhood tells us which pixels are spatially close.
Adjacency additionally depends on the set of pixels under consideration.
For example, in a binary image we may care only about pixels whose value is 1.
Two pixels can be called adjacent if:
- they satisfy the selected neighborhood relationship, and
- their values belong to the relevant set.
4. 4-, 8-, and m-connectivity

4-connectivity
Two pixels are adjacent if one lies in the other’s 4-neighborhood.
8-connectivity
Two pixels are adjacent if one lies in the other’s 8-neighborhood.
m-connectivity
Mixed adjacency is introduced to avoid certain ambiguities produced by 8-connectivity. The diagonal connection is accepted under a condition involving the common 4-neighbors The purpose is to avoid treating diagonal connections as connected in situations where they produce ambiguous connectivity.

5. Paths
A path is a sequence of pixels in which consecutive pixels satisfy the chosen adjacency rule.
Conceptually:
$$ p_0\rightarrow p_1\rightarrow p_2\rightarrow\cdots\rightarrow p_n. $$If every consecutive pair is adjacent according to the chosen definition, the sequence forms a valid path.
6. Connectivity
Two pixels are connected if there exists an allowed path between them.
This gives us a way to define image regions.
A connected component is a maximal set of mutually connected pixels.
Lecture 8 - Relationship of Adjacency and Connected Components Labeling
1. Concept of Adjacency
- Definition of Adjacency: Two pixels $p$ and $q$ are defined as adjacent if they are connected.
- Types of Adjacency: Because connectivity in digital image processing is categorized into three types, there are three corresponding types of adjacency depending on the connectivity used:
- 4-adjacency: Derived from 4-connectivity.
- 8-adjacency: Derived from 8-connectivity.
- m-adjacency (Mixed adjacency): Derived from m-connectivity.
2. Adjacency Between Image Regions
- The concept of adjacency extends beyond individual pixels to image regions (subsets of an image).
- Condition for Region Adjacency: Two image subsets $S_i$ and $S_j$ within an overall image are considered adjacent if there exists at least one point $p \in S_i$ and a point $q \in S_j$ such that $p$ and $q$ are adjacent.
- Visually, this means the two regions $S_i$ and $S_j$ appear directly adjacent to one another in the image space.
3. Paths and Path Length
- Path Definition: A path from pixel $p$ to pixel $q$ is defined as a sequence of distinct points $(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)$ where:
- $(x_0, y_0) = p$
- $(x_n, y_n) = q$
- Every subsequent pair of points $(x_{i-1}, y_{i-1})$ and $(x_i, y_i)$ is adjacent for all $i = 1, 2, \dots, n$.
- Path Length: If a path contains $n + 1$ total pixels (including the endpoints $p$ and $q$), the length of the path is defined as $n$.
4. Connected Components
- Connectivity between Pixels: Two pixels are connected if they are neighbours (adjacent in some sense) and possess similar intensity values.
- Connected Component Definition: Let $S$ be a subset of an image $I$. Two points $p, q \in S$ are connected in $S$ if there exists a path between $p$ and $q$ consisting entirely of pixels belonging to $S$.
- Connected Component: For any pixel $p \in S$, the set of all pixels in $S$ connected to $p$ forms a connected component of $S$.
- Key Properties:
- Any two pixels belonging to the same connected component are connected to each other.
- Distinct connected components are disjoint (pixels from one component are not connected to pixels of another component).
- Purpose: Connected components are used for group identification to group pixels belonging to the same object, enabling the extraction of region properties (such as shape and size).
5. Connected Components Labeling Problem
- Image Segmentation Context: Following threshold-based segmentation, pixels with intensity values above a threshold are assigned a value of $1$ (foreground / object of interest), while pixels with values below the threshold are assigned $0$ (background).
- Goal: Assign a unique group identification number (a label) to every pixel belonging to the same connected component, distinguishing distinct objects from one another.
6. Two-Pass Connected Components Labeling Algorithm
Algorithm Setup (Raster Scanning & 4-Connectivity)
- Scanning Order: The image is scanned in standard raster order β from left to right and top to bottom.
- 4-Connectivity Neighbors: When scanning pixel $p$ under 4-connectivity, two of its 4-neighbors have already been scanned:
- $r$: The neighbor directly above $p$.
- $t$: The neighbor directly to the left of $p$.
- Variables:
- $I(p)$: The binary intensity value at location $p$ ($0$ or $1$).
- $L(p)$: The label assigned to pixel $p$.
Step-by-Step Algorithm Rules
Pass 1: Initial Label Assignment & Equivalence Tracking
- Background Pixel ($I(p) = 0$):
- No label is assigned.
- Advance scan position to the next pixel.
- Foreground Pixel ($I(p) = 1$):
- Examine already-scanned neighbors $r$ (top) and $t$ (left):
- Case 1 (Both $r$ and $t$ are $0$):
- Assign a new label to $p$.
- Case 2 (Only one neighbor is $1$):
- Assign $p$ the same label as the active neighbor ($L(r)$ or $L(t)$).
- Case 3 (Both $r$ and $t$ are $1$):
- Sub-case A ($L(r) = L(t)$): Assign $L(p) = L(r)$ (or $L(t)$).
- Sub-case B ($L(r) \neq L(t)$): Assign $p$ one of the two labels (e.g., $L(r)$ or $L(t)$) and record $L(r)$ and $L(t)$ as equivalent in an equivalence table/list.
Pass 2: Label Resolution & Post-Processing
- Resolve Equivalence Classes: Process the recorded equivalent pairs to group all equivalent labels into unified classes.
- Label Reassignment: Re-scan the image and update each pixel’s label to the representative minimum label of its equivalence class.
- Outcome: Every pixel within the same connected region receives a single, unique label.
7. Example Walkthrough from Lecture

- First Pass Execution:
- Scanning starts from top-left. The first foreground pixel gets label 1.
- When encountering new isolated pixels whose top and left neighbors are $0$, new labels are assigned (label 2, label 3, label 5, etc.).
- When a pixel connects two regions with different labels (e.g., top neighbor has label 3, left has label 4), an equivalence note is logged.
- Equivalent Pairs Logged in Lecture:
- $(1, 2)$
- $(3, 4)$
- $(1, 5)$
- Second Pass Execution:
- Equivalent pairs are resolved into equivalence classes:
- Labels ${1, 2, 5} \rightarrow$ mapped to representative label 1.
- Labels ${3, 4} \rightarrow$ mapped to representative label 3.
- Image pixels are updated: all pixels labeled 2 or 5 become label 1, and all pixels labeled 4 become label 3.
- Final result: All pixels in each connected region share a unified, single label.

- Equivalent pairs are resolved into equivalence classes:
Lecture 9 β Application of Distance Measures
1. Fundamentals of Distance Measures & Metric Properties
Concept of Distance
- Point Coordinates: Given two points $p = (x, y)$ and $q = (s, t)$ in a spatial domain.
- Continuous Domain: Distance is conventionally represented as $D(p, q)$.
- Digital Domain: Euclidean distance is not the only metric used; digital image processing relies on multiple distance functions tailored to discrete grids (e.g., City Block, Chessboard).
Axioms/Properties of a Valid Distance Metric
For $D$ to qualify as a valid distance measure or distance metric among three points $p(x, y)$, $q(s, t)$, and $z(u, v)$, it must satisfy three core mathematical properties:
- Non-negativity & Identity: $$\mathbf{D(p, q) \ge 0} \quad \text{for any } p, q$$ $$\mathbf{D(p, q) = 0 \iff p = q}$$ (The distance of a point to itself is strictly zero).
- Symmetry: $$\mathbf{D(p, q) = D(q, p)}$$ (Measuring from $p$ to $q$ yields the same distance as measuring from $q$ to $p$).
- Triangle Inequality: $$\mathbf{D(p, z) \le D(p, q) + D(q, z)}$$ (The direct path between $p$ and $z$ is less than or equal to the path routed through a third point $q$).
2. Digital Distance Metrics
| Distance Metric | Mathematical Formula | Geometric Shape ($\le r$) | Key Characteristic |
|---|---|---|---|
| Euclidean Distance ($D_e$) | $D_e(p, q) = \sqrt{(x - s)^2 + (y - t)^2}$ | Circle of radius $r$ | Straight-line distance from continuous geometry. |
| City Block Distance ($D_4$) | $D_4(p, q) = \vert x - s \vert + \vert y - t \vert$ | Diamond of radius $r$ | Shortest path restricted to horizontal and vertical (4-neighbor) steps. |
| Chessboard Distance ($D_8$) | $D_8(p, q) = \max(\vert x - s \vert, \vert y - t \vert)$ | Square of side $2r$ | Shortest path allowing horizontal, vertical, and diagonal (8-neighbor) steps. |
3. Shape Analysis & Skeletonization Application
Why Use Skeletons for Shape Discrimination?
- Comparing raw binary shapes directly can fail when shapes are structurally dissimilar or complex.
- Skeleton Representation: A skeleton abstracts the original binary shape by stripping away redundant foreground pixels while retaining key topological structure, size, length, and breadth.

- Distinguishing Features Extracted from Skeletons:
- Number of Line Segments: E.g., Shape A’s skeleton has 5 segments, whereas Shape B’s skeleton has 10 segments.
- Junction / Intersection Points: Number of points where more than 2 line segments intersect (e.g., 2 points vs. 4 points).
4. Fire Propagation Analogy & Distance Transformation

Fire Propagation (Grassfire Model)
- Concept: Imagine the foreground region of a binary image is composed of a uniform, slow-burning material.
- Mechanism: Fire is ignited simultaneously along all outer boundary points of the foreground region.
- Quench Line: As fire fronts advance inward at a uniform rate, fire lines approaching from opposite boundaries meet and extinguish themselves.
- The locus of all self-extinguishing points forms the quench line, which represents the exact skeleton of the shape.
Distance Transformation ($DT$)
- Definition: A process that calculates the minimum distance (or time taken by the fire front) from every foreground pixel to its nearest boundary pixel.
- Output Image Type: Converted from a binary image to a gray-level image. The pixel intensities reflect proximity to the closest boundary.
- Extracting the Skeleton: The skeleton pixels correspond to points of curvature discontinuity (local intensity peaks) in the distance-transformed image.
- Impact of Metric Choice: Applying Euclidean, City Block, or Chessboard distance metrics produces slightly different distance transforms and skeletons, but all maintain equivalent global topology.


5. Basic Image Operations
Pixel-Level / Logical Operations
Operating on individual pixels across binary images:
- NOT (Inversion): Inverts binary values β background pixels ($0$ / black) become foreground ($1$ / white) and vice versa.
- AND: Performs pixel-by-pixel logical AND between two images.
- XOR: Performs pixel-by-pixel logical Exclusive OR.
Neighborhood Operations & Spatial Filtering
Replaces a central pixel’s intensity value $p$ with a computed function of the intensity values within its local neighborhood.
- Neighborhood Model ($3 \times 3$ window): $$\begin{bmatrix} z_1 & z_2 & z_3 \\ z_4 & z_5 & z_6 \\ z_7 & z_8 & z_9 \end{bmatrix}$$
- Simple Averaging Filter: Replacing center pixel $z_5$ with the arithmetic mean of its $3 \times 3$ neighborhood: $$z_5 = \frac{1}{9} \sum_{i=1}^{9} z_i$$
- General Template / Mask Operation (Weighted Sum): $$z = \sum_{i=1}^{9} w_i z_i$$
- When weights are set to $w_i = \frac{1}{9}$, the general template reduces to the simple neighborhood average.
- Applications of Template Operations:
- Noise filtering / smoothing
- Thinning of binary images
- Edge detection
Lecture 10 β Basic Transform
1. Overview & Objectives
- Core Subject: Mathematical transformations applied to points and geometric shapes in both 2D (two-dimensional) and 3D (three-dimensional) spatial domains.
- Key Topics Covered:
- 2D & 3D Basic Transformations: Translation, Rotation, and Scaling.
- Representation in Cartesian vs. Homogeneous / Unified Coordinate Systems.
- Composite (Concatenated) Transformations and the non-commutative nature of transformations.
- Transformations on Sets of Points (entire figures/shapes).
- Inverse Transformations for translation, rotation, and scaling.
- Application context: Homogeneous coordinates and perspective transformations form the foundation for camera image formation.
2. Homogeneous Coordinates & Unified Matrix Representation
- Motivation: Standard 2D translation is an additive vector operation ($x' = x + x_0, y' = y + y_0$), whereas scaling and rotation are matrix multiplications. Combining them naively results in an asymmetric equation: a matrix product plus an added vector.
- Homogeneous Coordinate Concept: To unify all transformations into single matrix multiplications, an extra dimension is appended to position vectors (e.g., converting $(x, y)$ to $(x, y, 1)^T$ in 2D, and $(X, Y, Z)$ to $(X, Y, Z, 1)^T$ in 3D).
- Advantages:
- Allows translation, scaling, and rotation to be expressed using unified square matrices ($3 \times 3$ for 2D, $4 \times 4$ for 3D).
- Enables easy concatenation of multiple sequential operations into a single combined transformation matrix.
- Plays a crucial role in modeling perspective projection and camera image formation.
3. Two-Dimensional (2D) Transformations
A. Translation
- Definition: Displaces a point $p(x, y)$ to a new location $p'(x', y')$ by offsets $x_0$ along the $x$-axis and $y_0$ along the $y$-axis.
- Equations: $$x' = x + x_0, \quad y' = y + y_0$$
- Homogeneous Matrix Form ($3 \times 3$): $$\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & x_0 \\ 0 & 1 & y_0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$
B. Rotation
- Definition: Rotates a point $p(x, y)$ around the origin by an angle $\theta$ in the clockwise direction.
- Derivation:
- Let the point $p$ be at distance $r$ from the origin with initial angle $\alpha$: $$x = r \cos\alpha, \quad y = r \sin\alpha$$
- Rotating by angle $\theta$ clockwise gives new coordinates $x' = r \cos(\alpha - \theta)$ and $y' = r \sin(\alpha - \theta)$.
- Expanding via trigonometric identities ($r\cos\alpha\cos\theta + r\sin\alpha\sin\theta$) yields: $$x' = x \cos\theta + y \sin\theta$$ $$y' = -x \sin\theta + y \cos\theta$$
- Matrix Representation(clockwise rotation): $$\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}$$
- Homogeneous Matrix Form ($3 \times 3$): $$\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos\theta & \sin\theta & 0 \\ -\sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$
C. Scaling
- Definition: Alters the size of an object relative to the origin by scaling factors $S_x$ along the $x$-axis and $S_y$ along the $y$-axis.
- Equations: $$x' = S_x \cdot x, \quad y' = S_y \cdot y$$
- Matrix Representation: $$\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} S_x & 0 \\ 0 & S_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}$$
- Homogeneous Matrix Form ($3 \times 3$): $$\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} S_x & 0 & 0 \\ 0 & S_y & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$
4. Three-Dimensional (3D) Transformations
In 3D, positions are represented in unified form as 4-element vectors $[X, Y, Z, 1]^T$ using $4 \times 4$ transformation matrices.
A. 3D Translation
- Displacement: Vector $(X_0, Y_0, Z_0)$.
- Equations: $X^* = X + X_0$, $Y^* = Y + Y_0$, $Z^* = Z + Z_0$.
- Matrix Representation ($4 \times 4$): $$\begin{bmatrix} X^* \\ Y^* \\ Z^* \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & X_0 \\ 0 & 1 & 0 & Y_0 \\ 0 & 0 & 1 & Z_0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \\ Y \\ Z \\ 1 \end{bmatrix}$$
B. 3D Scaling
- Scaling Factors: $S_x, S_y, S_z$ along the $x, y, z$ axes respectively.
- Effect: Scales up if factor $> 1$, scales down if factor $< 1$.
- Matrix Representation ($4 \times 4$): $$S = \begin{bmatrix} S_x & 0 & 0 & 0 \\ 0 & S_y & 0 & 0 \\ 0 & 0 & S_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
C. 3D Rotation
- 3D rotation depends on the specific axis of rotation:
- Rotation around the $Z$-axis ($R_\theta$): The $Z$-coordinate remains unchanged ($Z' = Z$), while $X$ and $Y$ coordinates rotate using the 2D rotation relations: $$R_\theta = \begin{bmatrix} \cos\theta & \sin\theta & 0 & 0 \\ -\sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
- Rotation around the $Y$-axis ($R_\beta$): Rotates by angle $\beta$ around the $Y$-axis: $$R_\beta = \begin{bmatrix} \cos\beta & 0 & -\sin\beta & 0 \\ 0 & 1 & 0 & 0 \\ \sin\beta & 0 & \cos\beta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
- Rotation around the $X$-axis ($R_\alpha$): Rotates by angle $\alpha$ around the $X$-axis: $$R_\alpha = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\alpha & \sin\alpha & 0 \\ 0 & -\sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
5. Composite Transformations & Non-Commutativity
A. Rotation Around an Arbitrary Point $q$
- Rotating a point $p$ directly around an arbitrary point $q$ (instead of the origin) is complex to express directly.
- Solution via Concatenation:
- Translate point $q$ to the origin using translation vector $-r$.
- Rotate the point around the origin by angle $\theta$ ($R_\theta$).
- Translate back by vector $+r$.
- The composite sequence is given by matrix multiplication.
B. Non-Commutativity (Order Matters)
- The order in which transformations are applied is critical.
- Example:
- Sequence 1: Apply Rotation ($R$), then Translation ($T$) $\rightarrow$ yields final point $v_2$.
- Sequence 2: Apply Translation ($T$), then Rotation ($R$) $\rightarrow$ yields final point $v_1$.
- Since $v_1 \neq v_2$, matrix transformations are not commutative ($T \cdot R \neq R \cdot T$).
6. Transforming Sets of Points (Geometric Objects)
- Concept: To transform an entire 2D or 3D object (e.g., a square with 4 vertices $p_1, p_2, p_3, p_4$), individual points do not need to be calculated separately in separate passes.
- Matrix Method:
- Store all vertex coordinates as column vectors inside a single point matrix: $$P = \begin{bmatrix} p_1 & p_2 & p_3 & p_4 \end{bmatrix}$$
- Multiply the transformation matrix by $P$ to obtain the transformed vertex matrix $P'$ in a single unified operation.
7. Inverse Transformations
Inverse transformations undo a previous operation and bring a point or shape back to its original position. They are determined directly by inspecting the original matrix parameters:
- Inverse Translation ($T^{-1}$):
- Negate the displacement offsets: replace $(X_0, Y_0, Z_0)$ with $(-X_0, -Y_0, -Z_0)$.
- Inverse Rotation ($R^{-1}$):
- Replace the rotation angle $\theta$ with $-\theta$.
- Inverse Scaling ($S^{-1}$):
- Replace scaling factors $(S_x, S_y, S_z)$ with their reciprocals $\left(\frac{1}{S_x}, \frac{1}{S_y}, \frac{1}{S_z}\right)$.
Lecture 11 β Image Formation I## 1. Overview & Coordinate Systems Setup
- Purpose: Provides a mathematical approximation of the physical 3D-to-2D image formation process inside a camera.
- Two Superimposed Coordinate Systems:
- 3D World Coordinate System: Denoted by $(X, Y, Z)$.
- Camera Coordinate System: Denoted by $(x, y, z)$.
- Alignment Assumptions:
- The world coordinate system and camera coordinate system are perfectly aligned and share the same origin $(0, 0, 0)$.
- The $X$-axis coincides with the $x$-axis, the $Y$-axis with the $y$-axis, and the $Z$-axis with the $z$-axis.
- Lens Position & Focal Length:
- The center of the camera lens is positioned along the optical axis at location $(0, 0, \lambda)$.
- The parameter $\lambda$ represents the $z$-coordinate of the lens center, which corresponds to the focal length of the camera.

2. Perspective Projection Equations (Similar Triangles)
- Goal: Determine the 2D image coordinates $(x, y)$ corresponding to a known 3D world point $(X, Y, Z)$ given camera focal length $\lambda$.
- Geometric Derivation: Derived by applying the geometric concept of similar triangles formed by the 3D point, the lens center, and the image plane.
- Image Coordinate Formulas:
- Horizontal Image Coordinate ($x$): $$x = \frac{\lambda X}{\lambda - Z}$$ - Vertical Image Coordinate ($y$): $$y = \frac{\lambda Y}{\lambda - Z}$$
3. Matrix Representation in Homogeneous Coordinates
- Homogeneous World Coordinates: To express the perspective projection as a linear matrix operation, the 3D world coordinate $(X, Y, Z)$ is converted into a homogeneous vector $\mathbf{w} = (kX, kY, kZ, k)^T$, where $k$ is an arbitrary scaling constant.
- Perspective Transformation Matrix ($P$): The perspective transformation is defined by the $4 \times 4$ matrix $P$: $$P = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -\frac{1}{\lambda} & 1 \end{bmatrix}$$
- Matrix Multiplication: Multiplying matrix $P$ by the homogeneous world coordinate vector $\mathbf{w}$ yields: $$P \mathbf{w} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -\frac{1}{\lambda} & 1 \end{bmatrix} \begin{bmatrix} kX \\ kY \\ kZ \\ k \end{bmatrix} = \begin{bmatrix} kX \\ kY \\ kZ \\ k\left(1 - \frac{Z}{\lambda}\right) \end{bmatrix}$$
- Conversion back to Cartesian Coordinates: Dividing the first two components by the 4th scale factor $k\left(1 - \frac{Z}{\lambda}\right) = k\left(\frac{\lambda - Z}{\lambda}\right)$ yields the Cartesian image coordinates: $$x = \frac{kX}{k\left(\frac{\lambda - Z}{\lambda}\right)} = \frac{\lambda X}{\lambda - Z}$$ $$y = \frac{kY}{k\left(\frac{\lambda - Z}{\lambda}\right)} = \frac{\lambda Y}{\lambda - Z}$$
- $Z= \frac{\lambda X}{\lambda - Z}$ is of no interest now and acts as free variable in inverse perspective transformation
4. Conclusions & Next Steps
- Role of $z$-Component: In the camera coordinate plane, the resulting $z$-value is $0$ because the imaging plane is assumed to lie directly in the $x$-$y$ plane.
- Forward Projection: The matrix $P$ allows mapping any 3D world point onto a 2D imaging plane.
- Future Topic (Inverse Transformation): The next lesson explores the inverse perspective transformation to evaluate whether a 3D world point can be uniquely recovered given its 2D image coordinates.
Lecture 12 β Image Formation II
1. Overview & Context
- Lecture Focus: This lecture examines the Inverse Perspective Transformation ($P^{-1}$) and the transition to a Generalized Camera Imaging Setup.
- Recap of Forward Perspective Projection:
- Forward perspective transformation ($P$) maps 3D world coordinates $(X, Y, Z)$ onto a 2D imaging plane to obtain camera coordinates $(x, y)$.
- Uppercase letters $(X, Y, Z)$ represent 3D world point coordinates $w$, while lowercase letters $(x, y, z)$ denote camera/image plane coordinates.
- The camera lens center (optical center) is situated along the optical axis at $(0, 0, \lambda)$, where $\lambda$ represents the focal length.
- Converts Cartesian coordinates $(X, Y, Z)$ into homogeneous coordinates $w_h = (kX, kY, kZ, k)^T$ using a non-zero scaling factor $k$.
- Forward Transformation Matrix ($P$): $$P = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -\frac{1}{\lambda} & 1 \end{bmatrix}$$
2. The Inverse Perspective Transformation Problem
A. The Objective of Inverse Perspective Projection
- Given a 2D image point $c$ with coordinates $(x_0, y_0, 0)$ on the imaging plane, the goal of $P^{-1}$ is to determine the original 3D world point $w(X, Y, Z)$ from which it originated.
B. Inverse Matrix Formulation ($P^{-1}$)
- The inverse of the perspective transformation matrix $P$ is given by: $$P^{-1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & \frac{1}{\lambda} & 1 \end{bmatrix}$$
C. Failure of Naive Inversion ($z = 0$)
- If we assume $z = 0$ for an image point $(x_0, y_0, 0)$ and form its homogeneous coordinate vector $c_h = (k x_0, k y_0, 0, k)^T$: $$w_h = P^{-1} c_h = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & \frac{1}{\lambda} & 1 \end{bmatrix} \begin{bmatrix} k x_0 \\ k y_0 \\ 0 \\ k \end{bmatrix} = \begin{bmatrix} k x_0 \\ k y_0 \\ 0 \\ k \end{bmatrix}$$
- Converting $w_h$ back to Cartesian coordinates by dividing by $k$ yields world point $w = (x_0, y_0, 0)$.
- Issue: This implies that the original 3D world point lies strictly on the imaging plane ($Z = 0$), which is false for general 3D objects in front of the camera.
3. Mathematical Derivation with $z$ as a Free Variable
To resolve the limitation of fixed $z = 0$, the $z$-component of the image point’s homogeneous coordinate is treated as a free variable $z$.
Step 1: Homogeneous Multiplication
- Represent the image point in homogeneous coordinates as $c_h = (k x_0, k y_0, k z, k)^T$.
- Multiply $c_h$ by $P^{-1}$ to calculate the homogeneous world coordinate $w_h$: $$w_h = P^{-1} c_h = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & \frac{1}{\lambda} & 1 \end{bmatrix} \begin{bmatrix} k x_0 \\ k y_0 \\ k z \\ k \end{bmatrix} = \begin{bmatrix} k x_0 \\ k y_0 \\ k z \\ \frac{k z}{\lambda} + k \end{bmatrix} = \begin{bmatrix} k x_0 \\ k y_0 \\ k z \\ k \left(\frac{\lambda + z}{\lambda}\right) \end{bmatrix}$$
Step 2: Conversion to Cartesian World Coordinates
- Divide each of the first three components by the 4th scaling component $k \left(\frac{\lambda + z}{\lambda}\right)$: $$X = \frac{k x_0}{k \left(\frac{\lambda + z}{\lambda}\right)} = \frac{\lambda x_0}{\lambda + z}$$ $$Y = \frac{k y_0}{k \left(\frac{\lambda + z}{\lambda}\right)} = \frac{\lambda y_0}{\lambda + z}$$ $$Z = \frac{k z}{k \left(\frac{\lambda + z}{\lambda}\right)} = \frac{\lambda z}{\lambda + z}$$
4. Line Equation & Geometric Interpretation
A. Many-to-One Mapping Nature
- Perspective projection is intrinsically a many-to-one mapping.
- All 3D points lying along a line passing through the camera optical center $(0, 0, \lambda)$ and the image point $(x_0, y_0, 0)$ project onto the exact same 2D image pixel $c$.
- Consequently, a single 2D image point $(x_0, y_0)$ cannot uniquely identify a single 3D point in world space without additional geometric constraints.
B. Parametric Projection Ray Equations
- Expressing $X$ and $Y$ in terms of $Z$ from the Cartesian formulas above yields the parametric equations for the 3D projection ray: $$X = \frac{x_0}{\lambda} (\lambda - Z)$$ $$Y = \frac{y_0}{\lambda} (\lambda - Z)$$
- Key Finding: While $P^{-1}$ cannot isolate a unique 3D point, it successfully identifies the exact 3D straight line containing all world points that map to $(x_0, y_0)$ on the image plane.
5. Requirements for Unique 3D Reconstruction
- To recover the unique 3D coordinates $(X, Y, Z)$ of a point from its 2D projection $(x_0, y_0)$, additional information is required.
- Example: Knowing the exact depth or world $Z$-coordinate value allows substituting $Z$ into the line equations $X = \frac{x_0}{\lambda}(\lambda - Z)$ and $Y = \frac{y_0}{\lambda}(\lambda - Z)$ to compute the exact 3D coordinates $(X, Y, Z)$.
6. Generalized Imaging Setup
- Aligned Model (Simplified): Assumes world origin and camera origin coincide, with perfectly parallel coordinate axes.
- Generalized Model (Realistic):
- In practice, the camera coordinate system and 3D world coordinate system are not aligned.
- Involves 3D rigid body transformations: a 3D translation to align origins, followed by 3D rotations around the axes to align coordinate orientation prior to perspective transformation.
Lecture 13 β Image Geometry I
1. Overview & Generalized Camera Model Motivation
- Simplified vs. Generalized Models: Previous camera models assumed that the camera coordinate system and the 3D world coordinate system were perfectly aligned with a shared origin at $(0, 0, 0)$. In physical setups, a camera is typically displaced and rotated arbitrarily in 3D space.
- Core Objective: Map any 3D world point $w(X, Y, Z)$ to its corresponding 2D camera image point $c(x, y)$ under arbitrary camera placement.
- Strategy: Apply a sequence of rigid-body coordinate transformations (translations and rotations) that bring the camera coordinate system and world coordinate system into alignment, followed by forward perspective projection.
2. Physical Setup & Geometric Parameters
The generalized setup models a camera mounted on a mechanical gimbal:
- Gimbal Center Displacement ($w_0$): The center of the gimbal is displaced from the 3D world origin $(0, 0, 0)$ by a displacement vector $w_0 = (X_0, Y_0, Z_0)^T$.
- Pan Angle ($\theta$): Rotation of the camera around the $Z$-axis by an angle $\theta$.
- Tilt Angle ($\alpha$): Rotation of the camera around the $X$-axis by an angle $\alpha$.
- Camera Center Offset ($r$): The center of the camera imaging plane (lens center) is further displaced relative to the gimbal center by a vector $r = (r_1, r_2, r_3)^T$ along the $x, y, z$ axes.
3. Step-by-Step Transformation Sequence & Matrices
- Relative Motion Principle: Moving the camera by a transformation vector corresponds to transforming all 3D world points in the exact opposite direction relative to the camera coordinate frame.
Step 1: Displacement of Gimbal Center ($G$)
- Displacing the gimbal center by $+w_0 = (X_0, Y_0, Z_0)^T$ shifts all 3D world points relative to the camera by $-w_0 = (-X_0, -Y_0, -Z_0)^T$.
- Translation Matrix ($G$): $$G = \begin{bmatrix} 1 & 0 & 0 & -X_0 \\ 0 & 1 & 0 & -Y_0 \\ 0 & 0 & 1 & -Z_0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
Step 2: Pan Rotation ($R_\theta$)
- Panning rotates the camera around the $Z$-axis by angle $\theta$, altering $x$ and $y$ coordinates while leaving $z$ unchanged.
- Pan Matrix ($R_\theta$): $$R_\theta = \begin{bmatrix} \cos\theta & \sin\theta & 0 & 0 \\ -\sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
Step 3: Tilt Rotation ($R_\alpha$)
- Tilting rotates the camera around the $X$-axis by angle $\alpha$, altering $y$ and $z$ coordinates while leaving $x$ unchanged.
- Tilt Matrix ($R_\alpha$): $$R_\alpha = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\alpha & \sin\alpha & 0 \\ 0 & -\sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
Combined Rotation Matrix ($R = R_\alpha R_\theta$)
Concatenating the tilt matrix $R_\alpha$ with the pan matrix $R_\theta$ yields the unified rotation matrix $R$:
$$R = R_\alpha R_\theta = \begin{bmatrix} \cos\theta & \sin\theta & 0 & 0 \\ -\sin\theta\cos\alpha & \cos\theta\cos\alpha & \sin\alpha & 0 \\ \sin\theta\sin\alpha & -\cos\theta\sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$Step 4: Camera Center Offset Translation ($T$)
- Displacing the center of the imaging plane from the gimbal center by vector $r = (r_1, r_2, r_3)^T$ translates world points relative to the camera frame by $-r = (-r_1, -r_2, -r_3)^T$.
- Translation Matrix ($T$): $$T = \begin{bmatrix} 1 & 0 & 0 & -r_1 \\ 0 & 1 & 0 & -r_2 \\ 0 & 0 & 1 & -r_3 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$
4. Full Unified Camera Model Pipeline
Transformed 3D Coordinates ($\hat{w}_h$): Applying transformations $G$, $R$, and $T$ in sequence to a homogeneous 3D world point $w_h = (X, Y, Z, 1)^T$ gives its aligned 3D position relative to the camera:
$$\hat{w}_h = T R G w_h = T R_\alpha R_\theta G w_h$$Homogeneous Image Point ($c_h$): Multiplying by the perspective projection matrix $P$ (where $\lambda$ is focal length) yields the homogeneous image coordinate vector:
$$c_h = P \hat{w}_h = P T R G w_h$$where:
$$P = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -\frac{1}{\lambda} & 1 \end{bmatrix}$$Cartesian Image Coordinates ($c$): Divide the first two components of $c_h = (kx, ky, kz, k)^T$ by the scale factor $k$ to obtain the final 2D pixel coordinates $(x, y)$ on the image plane.
5. Lecture Example Walkthrough
- Problem Setup:
- Camera imaging plane center located at $(0, 0, 1)^T$ in world coordinates.
- Corner of a 3D object located at $w = (1, 1, 0.2)^T$ in world space.
- Camera given a pan angle $\theta = 135^\circ$ around the $Z$-axis.
- Procedure:
- Translate 3D points relative to camera displacement by $(0, 0, -1)^T$.
- Apply pan rotation matrix for $\theta = 135^\circ$ around the $Z$-axis.
- Compute transformed 3D coordinate vector $\hat{w}_h = R_\alpha R_\theta T w_h$.
- Apply perspective transformation $P$ to calculate final 2D image coordinates.
Lecture 14 β Image Geometry II
1. Overview & Recap of Generalized Imaging Setup
- Generalized Setup: In realistic imaging scenarios, the 3D world coordinate system $(X, Y, Z)$ and the camera coordinate system $(x, y, z)$ are not aligned.
- Physical Parameters:
- Gimbal Displacement ($w_0$): The gimbal center is offset from the world origin by vector $w_0 = (X_0, Y_0, Z_0)^T$.
- Pan Angle ($\theta$): Rotation around the $Z$-axis.
- Tilt Angle ($\alpha$): Rotation around the $X$-axis.
- Lens Offset ($r$): Displacement of the camera lens center relative to the gimbal center by vector $r = (r_1, r_2, r_3)^T$.
- Full Mapping Equation: A 3D point in homogeneous coordinates $w_h = [X, Y, Z, 1]^T$ maps to a homogeneous image point $c_h$ via the product of four $4 \times 4$ transformation matrices: $$c_h = P T R G w_h = A w_h$$ where $G$ is gimbal translation, $R$ is combined pan/tilt rotation ($R = R_\alpha R_\theta$), $T$ is lens translation, $P$ is perspective projection, and $A$ is the combined $4 \times 4$ transformation matrix.
2. Internal vs. External Parameters & Motivation for Calibration
- Internal Parameters: The perspective matrix $P$ depends solely on the internal geometry of the camera, defined by its focal length $\lambda$.
- External Parameters: The matrices $T$, $R$, and $G$ depend entirely on the physical setup and arrangement of the camera relative to the world frame.
- The Measurement Problem:
- Physically measuring $w_0$, $r$, $\theta$, and $\alpha$ directly is difficult, prone to physical measurement errors, and cumbersome if the setup changes frequently.
- The Calibration Solution:
- Instead of measuring individual physical components, camera calibration directly estimates the 12 numerical elements of the combined $4 \times 4$ matrix $A = PTRG$ using a set of known 3D reference points and their observed 2D image coordinates.
3. Mathematical Derivation of Calibration Equations
Step 1: Homogeneous Form Setup
Let a 3D world point $w$ have coordinates $(X, Y, Z)$ with homogeneous representation $w_h = [X, Y, Z, 1]^T$ (setting scale factor $k = 1$ without loss of generality).
Multiplying $w_h$ by the combined $4 \times 4$ transformation matrix $A$ yields the homogeneous image vector $c_h = [c_{h1}, c_{h2}, c_{h3}, c_{h4}]^T$:
$$c_{h1} = a_{11}X + a_{12}Y + a_{13}Z + a_{14}$$ $$c_{h2} = a_{21}X + a_{22}Y + a_{23}Z + a_{24}$$ $$c_{h3} = a_{31}X + a_{32}Y + a_{33}Z + a_{34}$$ $$c_{h4} = a_{41}X + a_{42}Y + a_{43}Z + a_{44}$$Step 2: Conversion to Cartesian Image Coordinates
The Cartesian image plane coordinates $(x, y)$ are obtained by dividing the first two homogeneous components by the 4th scale factor $c_{h4}$:
$$x = \frac{c_{h1}}{c_{h4}} = \frac{a_{11}X + a_{12}Y + a_{13}Z + a_{14}}{a_{41}X + a_{42}Y + a_{43}Z + a_{44}}$$ $$y = \frac{c_{h2}}{c_{h4}} = \frac{a_{21}X + a_{22}Y + a_{23}Z + a_{24}}{a_{41}X + a_{42}Y + a_{43}Z + a_{44}}$$Step 3: Linear Algebraic Formulation
Rearranging the expressions by cross-multiplying gives two linear equations per point:
$$a_{11}X + a_{12}Y + a_{13}Z + a_{14} - a_{41}Xx - a_{42}Yx - a_{43}Zx - a_{44}x = 0$$ $$a_{21}X + a_{22}Y + a_{23}Z + a_{24} - a_{41}Xy - a_{42}Yy - a_{43}Zy - a_{44}y = 0$$4. Calibration System Solvability & Requirements
- Number of Unknowns: There are 12 matrix elements ($a_{11}, a_{12}, a_{13}, a_{14}, a_{21}, a_{22}, a_{23}, a_{24}, a_{41}, a_{42}, a_{43}, a_{44}$) in matrix $A$.
- Equations per Point: Each known 3D point $(X, Y, Z)$ and its corresponding measured 2D image location $(x, y)$ provides 2 independent linear equations.
- Minimum Calibration Points Required: To solve for the 12 unknown elements, a minimum of 6 known, non-coplanar 3D reference points is required ($6 \text{ points} \times 2 \text{ equations/point} = 12 \text{ equations}$).
- Post-Calibration Utility: Once matrix $A$ is solved:
- Any 3D world point $(X, Y, Z)$ can be mapped directly to its 2D image coordinates $(x, y)$.
- Given any 2D image point $(x, y)$, the inverse transformation yields the exact 3D line equation containing the original world point.
Lecture 15: Stereo Imaging Model - II
1. Motivation for Stereo Imaging
- Single-Camera Depth Ambiguity: Using a single camera with inverse perspective transformation mapping a 2D image point $c(x_0, y_0)$ returns a 3D line ray rather than a unique 3D point $(X, Y, Z)$.
- Stereo Imaging Solution: By capturing the same scene using two calibrated cameras positioned at different viewing angles:
- The inverse perspective transformation from the left image provides the equation of a first 3D line ray.
- The inverse perspective transformation from the right image provides the equation of a second 3D line ray.
- The point of intersection of these two 3D rays uniquely determines the exact $(X, Y, Z)$ coordinates of the 3D world point $w$.
2. General vs. Aligned (Standard) Stereo Setup
A. General Stereo Setup
- The left and right cameras have arbitrary, unaligned positions and orientations.
- Mathematical Requirement: Requires coordinate system transformation matrices (translations, rotations, and scaling if image resolutions differ) to align the two camera coordinate frames before applying stereo equations.
B. Standard (Parallel) Aligned Stereo Setup
To simplify the mathematics, a parallel configuration is established with the following assumptions:
- Both cameras are identical, sharing the same focal length $\lambda$ and image resolution.
- The coordinate system of Camera 1 (Left Camera, $(x_1, y_1)$) is perfectly aligned with the 3D World Coordinate System $(X, Y, Z)$.
- Camera 2 (Right Camera, $(x_2, y_2)$) is displaced strictly along the horizontal $X$-axis by a baseline distance $B$.
- There is zero displacement along the $Y$-axis or $Z$-axis between the two cameras.
3. Mathematical Derivation of Depth ($Z$) and 3D Coordinates
A. Coordinate Relationships
For any 3D world point $w$:
- $Z_1 = Z_2 = Z$ (identical depth relative to both cameras).
- $Y_1 = Y_2 = Y$ (identical vertical coordinate).
- $X_2 = X_1 + B$ (horizontal shift by baseline distance $B$).
B. Forward Projection Equations
Left Camera Coordinates $(x_1, y_1)$:
$$x_1 = \frac{\lambda X_1}{\lambda - Z}, \quad y_1 = \frac{\lambda Y_1}{\lambda - Z}$$Right Camera Coordinates $(x_2, y_2)$:
$$x_2 = \frac{\lambda X_2}{\lambda - Z} = \frac{\lambda (X_1 + B)}{\lambda - Z}, \quad y_2 = \frac{\lambda Y_2}{\lambda - Z} = \frac{\lambda Y_1}{\lambda - Z}$$
C. Disparity Definition & Depth ($Z$) Equation
Expanding the right camera’s horizontal image coordinate equation:
$$x_2 = \frac{\lambda X_1}{\lambda - Z} + \frac{\lambda B}{\lambda - Z} = x_1 + \frac{\lambda B}{\lambda - Z}$$Rearranging gives the difference in $x$-coordinates between the two images, defined as Disparity:
$$\text{Disparity} = d = x_2 - x_1 = \frac{\lambda B}{\lambda - Z}$$Solving directly for depth $Z$:
$$\lambda - Z = \frac{\lambda B}{x_2 - x_1} \implies Z = \lambda - \frac{\lambda B}{x_2 - x_1}$$- Key Finding: The 3D depth $Z$ can be computed knowing only:
- Focal length $\lambda$.
- Baseline distance $B$ between the two cameras.
- Disparity $(x_2 - x_1)$ measured across the left and right images.
D. Full 3D Coordinate Reconstruction
Once $Z$ is computed from the disparity formula, the remaining 3D coordinates $X$ and $Y$ are derived directly from the left image point $(x_1, y_1)$:
$$X = \frac{x_1}{\lambda}(\lambda - Z), \quad Y = \frac{y_1}{\lambda}(\lambda - Z)$$4. The Stereo Correspondence Problem & Search Optimization
A. The Correspondence Problem
- To compute disparity $(x_2 - x_1)$, we must match a point $c_L(x_1, y_1)$ in the left image to its corresponding projection $c_R(x_2, y_2)$ in the right image.
- Brute-Force Complexity: Unconstrained searching for matching points across two full $N \times N$ images requires evaluating up to $O(N^4)$ candidate combinations in the worst case.
B. Same-Row Constraint (Epipolar Optimization)
- Because the cameras are displaced only along the $X$-axis ($Y_1 = Y_2$ and $Z_1 = Z_2$): $$y_1 = \frac{\lambda Y_1}{\lambda - Z} = \frac{\lambda Y_2}{\lambda - Z} = y_2$$
- Constraint Principle: The vertical image coordinate $y_1$ in the left image is strictly equal to $y_2$ in the right image ($y_1 = y_2$).
- Computational Advantage: For a point $c_L$ on row $i$ in the left image, its matching point $c_R$ in the right image is guaranteed to lie on the exact same row $i$. Searching is reduced from a 2D image grid down to a 1D horizontal scanline.
5. Limitations of Stereo Imaging
- Common Field of View / Overlap Requirement:
- 3D reconstruction is only possible for points lying within the overlapping field of view of both cameras.
- Points visible to only one camera (due to field-of-view limits or occlusion) cannot be matched, making 3D coordinate estimation impossible for those regions.
Master Checklist β If You Want to Speedrun Lectures 1β15
A. Digital image fundamentals
- Define digital image processing.
- Explain the three broad motivations for DIP.
- Explain the complete image-processing pipeline.
- Distinguish enhancement for humans from machine vision.
B. Digitization
- Define $f(x,y)$.
- Explain sampling.
- Explain quantization.
- Explain why both are necessary.
- Define spatial resolution.
- Define intensity/gray-level resolution.
- Explain bandwidth.
- Explain Fourier spectrum conceptually.
- State the Nyquist condition.
- Explain aliasing.
- Explain spectral replicas caused by sampling.
- Explain 2-D spatial frequency.
C. Reconstruction
- Understand the sampling comb.
- Understand convolution.
- Understand multiplication/convolution duality.
- Understand spectral replication.
- Understand reconstruction filtering.
- Extend the idea from 1-D signals to 2-D images.
D. Quantization
- Define quantization error.
- Define transition/decision levels.
- Define reconstruction levels.
- Write mean-square error.
- Understand LloydβMax quantization.
- Know the centroid/conditional-mean reconstruction condition.
- Know the midpoint decision-level condition.
- Understand iterative optimization.
- Understand the uniform-input special case.
- Know: $D=\frac{q^2}{12}$.
- Know: $q=\frac{A}{2^B}$.
E. Pixel relationships
- 4-neighborhood.
- Diagonal neighborhood.
- 8-neighborhood.
- 4-adjacency.
- 8-adjacency.
- m-adjacency.
- Path.
- Connectivity.
- Connected component.
- Connected-component labeling.
- Two-pass labeling.
- Equivalence classes.
F. Distance and image operations
- Euclidean distance.
- City-block distance.
- Chessboard distance.
- Distance transform.
- Skeleton.
- Pixel-wise arithmetic operations.
- Pixel-wise logical operations.
- Neighborhood operations.
G. Transformations
- Translation.
- Scaling.
- Rotation.
- Inverse transformations.
- 2-D transformations.
- 3-D transformations.
- Homogeneous coordinates.
- Transformation composition.
- Non-commutativity of transformations.
- Perspective transformation.
H. Camera geometry
- World coordinate system.
- Camera coordinate system.
- Image coordinate system.
- Pixel coordinate system.
- Pinhole camera model.
- Perspective projection: $x=fX/Z,\quad y=fY/Z$.
- Camera translation.
- Camera rotation.
- Rigid world-to-camera transformation.
- Inverse perspective transformation.
- Viewing ray interpretation.
I. Stereo
- Stereo camera setup.
- Corresponding points.
- Disparity.
- Baseline.
- Triangulation intuition.
- Depth-disparity relationship: $Z=\frac{fB}{d}$.
- Why large disparity means small depth.
- Why correspondence is the hard practical problem.
Essential Equations β Lectures 1β15
| Category | Concept | Equation |
|---|---|---|
| Sampling & Signal | Discrete Sampling | $f[m,n] = f(m\Delta_x, n\Delta_y)$ |
| Nyquist Condition | $f_s \geq 2B$ | |
| Quantization | Quantization Error | $e = u - u'$ |
| Mean-Square Error (MSE) | $D = E[(u - u')^2]$ | |
| LloydβMax Reconstruction | $r_k = \frac{\int_{t_k}^{t_{k+1}} u\,p_u(u)\,du}{\int_{t_k}^{t_{k+1}} p_u(u)\,du}$ | |
| Uniform Step Size | $q = \frac{A}{2^B}$ | |
| Uniform Quantizer MSE | $D = \frac{q^2}{12}$ | |
| Distance Metrics | Euclidean Distance | $D_E(p,q) = \sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$ |
| City-Block Distance ($D_4$) | $D_4(p,q) = \vert x_1-x_2 \vert + \vert y_1-y_2 \vert$ | |
| Chessboard Distance ($D_8$) | $D_8(p,q) = \max(\vert x_1-x_2 \vert, \vert y_1-y_2 \vert)$ | |
| 2D Transformations | Translation & Scaling | $x' = x + t_x, \quad y' = y + t_y \quad \vert \quad x' = s_x x, \quad y' = s_y y$ |
| Rotation Matrix | $\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}$ | |
| Camera Geometry | World-to-Camera | $P_c = R P_w + t \quad \text{or} \quad P_c = R(P_w - C)$ |
| Perspective Projection | $x = f \frac{X_c}{Z_c}, \quad y = f \frac{Y_c}{Z_c}$ | |
| Stereo Vision | Depth from Disparity | $Z = \lambda - \frac{\lambda B}{d} \quad \left(\text{or } Z = \frac{fB}{d}\right)$ |
What Not to Confuse
Sampling vs quantization
Sampling:
“Where do I measure?”
Quantization:
“What numerical value am I allowed to store?”
Neighborhood vs adjacency
Neighborhood:
spatially nearby locations.
Adjacency:
a relationship between pixels based on a chosen neighborhood and the relevant pixel set.
Connectivity vs distance
Connectivity asks:
“Can I get from here to there through valid neighboring pixels?”
Distance asks:
“How far apart are these two locations according to a chosen metric?”
Perspective projection vs camera pose
Camera pose:
Where is the camera and how is it oriented?
Perspective projection:
Given a point in camera coordinates, where does it appear in the image?
Single-view reconstruction vs stereo
Single camera:
$$ \text{pixel}\rightarrow\text{3-D ray}. $$Stereo:
$$ \text{two pixels}\rightarrow\text{two rays}\rightarrow\text{3-D point/depth}. $$The Main Story to Remember
If you remember only one conceptual chain from the first 15 lectures, remember this:
$$ \boxed{ \text{Physical scene} \rightarrow \text{continuous image} \rightarrow \text{sampling} \rightarrow \text{quantization} \rightarrow \text{digital image} } $$Then:
$$ \boxed{ \text{digital pixels} \rightarrow \text{neighborhood} \rightarrow \text{connectivity} \rightarrow \text{regions / objects} } $$Then:
$$ \boxed{ \text{coordinates} \rightarrow \text{transformations} \rightarrow \text{camera} \rightarrow \text{projection} } $$And finally:
$$ \boxed{ \text{two projections} \rightarrow \text{disparity} \rightarrow \text{depth} \rightarrow \text{3-D reconstruction}. } $$That is the conceptual progression that the lecturer is building across Lectures 1β15.