📚 Chapters

🖼️ Digital Image Processing

Unit 3 — Image Compression & Segmentation

🗜️Chapter 1 — Image Compression
🗜️ CHAPTER 1 — IMAGE COMPRESSION MIND MAP
Why → Reduce storage and transmission time. CR = n1 / n2
Redundancies → Coding | Interpixel | Psychovisual
Quality → Fidelity: objective (RMS, PSNR) and subjective
Model → Source encoder (mapper, quantizer, symbol encoder) + channel encoder
Methods → Lossless: Huffman, arithmetic, LZW, RLE | Lossy: predictive, transform (JPEG) | JPEG 2000 (wavelet)

1. Introduction to Image Compression

📖 Image compression: Reducing the amount of data needed to represent an image, by removing redundant (repeated or unnecessary) data. Decompression rebuilds the image.
💡 Why needed? A 1024 × 1024 image with 8 bits per pixel is about 1 MB. A colour image is 3 MB, and a video needs 25–30 such frames every second. Without compression, storing and sending them would be very costly.
📐 Compression ratio and relative redundancy
Compression ratio: CR = n1 / n2 (n1 = original size, n2 = compressed size)
Relative data redundancy: RD = 1 − 1 / CR
Example: 10 MB → 2 MB gives CR = 5 : 1 and RD = 1 − 1/5 = 0.8 (80% of the data was redundant)
Lossless (error-free)Lossy
Rebuilt imageExactly the same as the originalClose to the original, not identical
Compression ratioLow (about 2 : 1 to 3 : 1)High (10 : 1 or more)
Used forMedical images, documents, textPhotos, video, web images
ExamplesHuffman, LZW, RLE, PNGJPEG, JPEG 2000 (lossy), MPEG

2. Redundancies and Their Removal Methods

📖 Redundancy: Data that gives no extra useful information. There are three types in images.
1. Coding redundancySame number of bits for every gray level, even though some levels occur much more often. Remove by: variable-length codes (Huffman, arithmetic).
2. Interpixel redundancyNeighbouring pixels (in space or between video frames) are highly similar. Remove by: predictive coding, run-length coding, transforms.
3. Psychovisual redundancyThe eye ignores some details (fine texture, small colour changes). Remove by: quantization (lossy).
💡 Examples:
Coding: a very common gray level gets a 1-bit code and a rare one gets a longer code.
Interpixel: the row 100, 100, 100, 101 can be stored as 100 followed by differences 0, 0, 1.
Psychovisual: reducing 256 gray levels to 64 may be unnoticeable.
Entropy H = −Σ pk log2 pk (bits/pixel) is the minimum average number of bits needed to code the source without loss.

3. Fidelity Criteria

📖 Fidelity criteria measure how close the decompressed image f̂(x,y) is to the original f(x,y), because lossy compression changes the image.
TypeMeasureMeaning
ObjectiveError e(x,y) = f̂(x,y) − f(x,y)Pixel difference
RMS error: erms = [ (1/MN) ΣΣ (f̂ − f)² ]1/2Average error size, lower is better
MSE = (1/MN) ΣΣ (f̂ − f)²Mean squared error
PSNR = 10 log10 [ (L−1)² / MSE ] dBHigher is better
SubjectiveRating by human viewersExcellent, Fine, Passable, Marginal, Inferior, Unusable
📐 Example
8-bit image (L − 1 = 255), MSE = 25
PSNR = 10 log10(255² / 25) = 10 log10(2601) ≈ 34.15 dB
Objective measures are easy to compute but may not match what people see. That is why subjective rating is also used.

4. Image Compression Models — Source Encoder and Decoder

📖 Compression system: An encoder (compression) and a decoder (decompression) connected through a channel.
Source encoder: Mapper→Quantizer→Symbol encoder→Channel encoder→Channel
Channel decoder→Source decoder: Symbol decoder→Inverse mapper→f̂(x,y)
Top row: compression side. Bottom row: decompression side. The quantizer is the only lossy step (skipped in lossless compression).
BlockJobRedundancy removed
MapperConverts pixels into a form better for compression (differences, transform coefficients, run lengths). ReversibleInterpixel
QuantizerReduces the accuracy of the mapper output. Irreversible, so it is skipped in lossless codingPsychovisual
Symbol encoderAssigns variable-length codes to the outputCoding
Channel encoderAdds controlled redundancy (e.g. Hamming code) so channel errors can be detected or corrected—

5. Error-Free (Lossless) Compression

📖 Lossless compression: The decompressed image is exactly the original. It removes coding and interpixel redundancy only.
1. Huffman coding
Gives shorter codes to more probable symbols. Steps: sort symbols by probability → merge the two smallest into one → repeat until one is left → assign 0 and 1 on each merge. The code is prefix-free, so it can be decoded without separators.
MergeProbabilities combinedNew probability
10.04 + 0.060.1
20.1 + 0.10.2
30.1 + 0.20.3
40.3 + 0.30.6
50.4 + 0.61.0
SymbolProbabilityHuffman codeLength
a10.401
a20.3102
a30.111104
a40.111114
a50.0611014
a60.0411004
📐 Result
Average length Lavg = Σ p·length = 2.2 bits/symbol
Fixed-length code needs 3 bits/symbol
Compression ratio = 3 / 2.2 ≈ 1.36
Entropy H ≈ 2.14 bits/symbol (Lavg is just above it)
The exact bits can differ when probabilities tie, but the average length is always the same (2.2).
2. Other lossless methods
MethodIdeaExample
Run-length coding (RLE)Store (value, run length) instead of repeating valuesAAAABBBCC → 4A 3B 2C. Binary row 0000011100 → (0×5)(1×3)(0×2)
Arithmetic codingCodes the whole message as one number between 0 and 1, by repeatedly narrowing an interval by symbol probabilitiesGets closer to entropy than Huffman, no whole-bit limit per symbol
LZW (dictionary)Builds a dictionary of repeated patterns while reading, and outputs dictionary indexesUsed in GIF, TIFF
Bit-plane codingSplit the gray image into binary bit planes and code each (RLE)Good for images with large flat areas

6. Lossy Compression

📖 Lossy compression: Accepts a small, controlled loss of information to get a much higher compression ratio. The loss comes from the quantizer.
💡 Analogy: Rounding prices to the nearest 10 rupees. You store fewer digits, and the total changes only slightly.
  • Quality and compression ratio trade off: more compression, more distortion
  • Removes psychovisual redundancy that the eye hardly notices
  • Main lossy methods: lossy predictive coding and transform coding
  • Quality is checked with fidelity criteria (PSNR, subjective rating)

7. Lossless and Lossy Predictive Coding

📖 Predictive coding: Predict each pixel from its previous (neighbouring) pixels and code only the prediction error en = fn − f̂n. The errors are small and mostly near 0, so they need fewer bits.
Lossless predictive coding
fn→− predictor f̂n→error en→symbol encoder (Huffman)
💡 Example (predictor = previous pixel): pixels 100, 102, 101, 103 → send 100, then errors +2, −1, +2. The decoder adds each error to the previous value and rebuilds the exact pixels.
Lossy predictive coding (DPCM)
A quantizer is placed inside the loop. The error is quantized to ėn, and the predictor uses the reconstructed values (not the originals), so the encoder and decoder stay in step and errors do not pile up.
nOriginal fError eQuantized ė (step 4)Reconstructed
0100——100
110444104
210954108
310800108
Pixel 3: original 109, reconstructed 108. This small difference is the loss. Delta modulation is the simplest DPCM with a 1-bit quantizer; it shows granular noise in flat areas and slope overload on sharp edges.

8. Transform-Based Compression

📖 Transform coding: Divide the image into small blocks (usually 8 × 8), apply a transform such as DCT, quantize the coefficients and then code them. Most energy goes into a few low-frequency coefficients, so the small high-frequency ones can be dropped.
8×8 blocks→DCT→Quantization (lossy)→Zigzag scan→Run-length + Huffman→Compressed data
💡 Why DCT? Strong energy compaction (close to the optimal KL transform), real-valued, fast algorithms, and fewer block-edge problems than DFT.
015614152728
2471316262942
38121725304143
911182431404453
1019233239455254
2022333846515560
2134374750565961
3536484957586263
Zigzag scan order of an 8 × 8 block of DCT coefficients. 0 = DC (low frequency). The scan ends at 63 (highest frequency).
Zonal codingThreshold coding
IdeaKeep a fixed zone of low-frequency coefficientsKeep coefficients whose magnitude is above a threshold
ZoneSame for all blocksChanges block by block (adaptive)
Blocking artifacts: At high compression, the 8 × 8 block edges become visible.
JPEG (baseline) in short
  • 8 × 8 DCT, then quantization using a quantization table
  • DC coefficient coded by difference from the previous block; AC coefficients zigzag scanned and run-length coded
  • Final stage: Huffman coding

9. JPEG 2000 Standard

📖 JPEG 2000: An image compression standard based on the discrete wavelet transform (DWT) instead of the block DCT. It supports both lossless and lossy compression in one system.
Image (tiles)→Level shift + colour transform→DWT→Quantization→EBCOT coding→Codestream
StageDetail
Colour transformReversible (RCT) for lossless, irreversible (ICT) for lossy
DWT5/3 filter (reversible, lossless) or 9/7 filter (lossy)
QuantizationUsed only in lossy mode
EBCOTEmbedded Block Coding with Optimized Truncation: context modelling + arithmetic coding of code blocks, then rate control
JPEGJPEG 2000
Transform8 × 8 block DCTWavelet (DWT) on whole image or tiles
Artifacts at high compressionBlockingBlurring (no blocks)
LosslessSeparate modeBuilt in (same codestream)
ScalabilityLimitedStrong: by resolution, quality, region of interest
ComplexityLowerHigher
File type.jpg.jp2
Advantages: better quality at low bit rates, progressive transmission, region of interest coding, one file for many qualities.
✂️Chapter 2 — Image Segmentation
✂️ CHAPTER 2 — IMAGE SEGMENTATION MIND MAP
Idea → Divide the image into regions or objects
Discontinuity based → Points, lines, edges (Sobel, Prewitt, Laplacian, LoG, Canny)
Edge linking → Local processing, Hough transform
Thresholding → Global, Otsu, adaptive
Region based → Region growing, region splitting and merging

1. Introduction to Image Segmentation

📖 Image segmentation: Dividing an image into regions or objects that share a property (intensity, colour, texture). It is the first step to find boundaries and recognise objects.
💡 Analogy: Cutting objects out of a photo with scissors. Each cut-out piece is one segment.
Discontinuity-basedFind sudden changes in intensity: points, lines, edges.
Similarity-basedGroup pixels that are alike: thresholding, region growing, splitting and merging.
Rules for a segmentation of image R into regions R1 … Rn
  1. The regions together cover the whole image: ∪ Ri = R
  2. Each region Ri is a connected set
  3. Regions do not overlap: Ri ∩ Rj = ∅ for i ≠ j
  4. Pixels of a region share a property: Q(Ri) = TRUE
  5. Two different adjacent regions differ: Q(Ri ∪ Rj) = FALSE

2. Detection of Discontinuities — Points and Lines

📖 Mask processing: Place a 3 × 3 mask on the image. The response is R = w1z1 + w2z2 + … + w9z9 (multiply and add). A large |R| means a discontinuity.
  • Point detection: the mask sum is 0, so flat areas give 0. A point is found if |R| ≥ T
  • Line detection: use four masks (horizontal, vertical, +45°, −45°). The mask with the largest response gives the line direction
-1-1-1
-18-1
-1-1-1
Point
-1-1-1
222
-1-1-1
Horizontal line
-12-1
-12-1
-12-1
Vertical line
-1-12
-12-1
2-1-1
+45° line
2-1-1
-12-1
-1-12
−45° line
Green = positive weights, red = negative weights. Each mask adds up to 0.

3. Edge Detection

📖 Edge: A set of pixels where intensity changes abruptly. Edges mark boundaries of objects.
Intensity (ramp edge)1st derivative: peak2nd derivative: zero crossingedge
Edge detection uses the 1st derivative (look for a peak) or the 2nd derivative (look for a zero crossing).
📐 Gradient
∇f = [Gx, Gy] = [∂f/∂x, ∂f/∂y]
Magnitude M(x,y) = √(Gx² + Gy²) ≈ |Gx| + |Gy|
Direction α(x,y) = tan−1(Gy / Gx) (the edge is at 90° to it)
First-derivative masks
-101
-202
-101
Sobel Gx
-1-2-1
000
121
Sobel Gy
-101
-101
-101
Prewitt Gx
-1-1-1
000
111
Prewitt Gy
Roberts uses 2 × 2 cross masks [−1 0; 0 1] and [0 −1; 1 0]. Sobel gives more weight (2) to the centre row or column, so it also smooths noise a little.
📐 Sobel worked example
Region z = [10 10 10; 10 10 10; 100 100 100] (dark above, bright below)
Gx = 0 (no change left to right)
Gy = (100 + 200 + 100) − (10 + 20 + 10) = 360
M = √(0² + 360²) = 360 → a strong horizontal edge
DetectorIdeaRemark
Laplacian ∇²f2nd derivative, zero crossing marks the edgeVery sensitive to noise, gives double edges, no direction
LoG (Marr–Hildreth)Smooth with a Gaussian, then Laplacian, then find zero crossingsLess noise sensitive
CannyGaussian smoothing → gradient → non-maximum suppression → hysteresis thresholding (2 thresholds)Thin, well-connected edges, widely used

4. Edge Linking and Boundary Detection

📖 Edge linking: Edge detectors leave gaps and noise. Edge linking joins edge pixels into continuous boundaries.
1. Local processing
Look at a small neighbourhood (3 × 3 or 5 × 5) around every edge pixel (x, y). Link a neighbour (s, t) if it is similar in strength and direction: |M(s,t) − M(x,y)| ≤ E and |α(s,t) − α(x,y)| ≤ A.
2. Global processing — Hough transform
Finds lines among scattered edge points. A line y = ax + b becomes a point (a, b) in parameter space. Each edge point votes for all lines passing through it, and the cell with the most votes is the line.
Image space (x, y)Parameter space (a, b)peak at a = 1, b = 0 (y = x)
💡 Example: points (1,1), (2,2), (3,3). Each gives a line b = −xa + y: b = −a + 1, b = −2a + 2, b = −3a + 3. All three meet at (a = 1, b = 0), so the line is y = 1·x + 0.
Vertical lines have infinite slope, so the polar form ρ = x cos θ + y sin θ is used in practice. Other boundary methods: boundary following, graph-theoretic (minimum cost path).

5. Thresholding

📖 Thresholding: Convert a gray image to a binary one: g(x,y) = 1 if f(x,y) > T, else 0. Objects and background get different labels.
backgroundobjectTgray level →
A bimodal histogram has two peaks. The threshold T is placed in the valley between them.
Basic global thresholding (iterative)
  1. Choose an initial threshold T (for example the mean of all pixels)
  2. Split pixels into G1 (> T) and G2 (≤ T)
  3. Find the mean m1 of G1 and m2 of G2
  4. New T = ½ (m1 + m2)
  5. Repeat steps 2 to 4 until T changes by less than a small value
💡 Example: pixels 10, 12, 11, 9, 200, 205, 198, 203. Start T = mean ≈ 106.0. m1 = 201.5, m2 = 10.5, so T = 106.0. The result does not change, so the final threshold is about 106.
TypeIdea
GlobalOne T for the whole image. Works for uniform lighting and bimodal histograms
Otsu's methodChooses T that maximises the between-class variance σB² = ω1ω2(μ1 − μ2)²
Adaptive (local)Different T for each small region. Handles uneven illumination
Multiple thresholdsT1, T2 split the image into 3 classes

6. Region-Oriented Segmentation

📖 Region-based segmentation groups pixels by similarity directly, instead of searching for edges.
1. Region growing
Steps
  1. Pick one or more seed pixels
  2. Add a neighbouring pixel if it satisfies the similarity rule (e.g. |intensity − seed| ≤ T)
  3. Keep growing until no neighbour qualifies
  4. Repeat with new seeds for the other regions
💡 Example: seed = top-left pixel (10), rule |f − 10| ≤ 5, 8-connectivity.
1012808285
1113798184
1011128386
910111287
89101112
Image
1012808285
1113798184
1011128386
910111287
89101112
Grown region (green)
The 80s are too different from the seed, so the region keeps only the dark (low-value) pixels.
2. Region splitting and merging
Start with the whole image. Split any region into 4 quadrants if Q(R) is FALSE (quadtree). Then merge adjacent regions Ri, Rj if Q(Ri ∪ Rj) is TRUE. No seed points are needed.
Edge-basedThresholdingRegion-based
Looks atSudden changesGray-level histogramSimilar neighbours
StrengthFinds boundariesSimple, fastClosed, connected regions
WeaknessGaps, noiseFails with uneven lightDepends on seeds and rule
📚Self-Study Topic

1. Self-Study — Machine Learning Techniques

📖 Machine learning (ML): Computers learn patterns from data instead of following fixed rules. In image processing, ML decides what an image or a pixel is, using features (intensity, colour, texture, shape).
TypeIdeaExample in image processing
SupervisedLearn from labelled dataClassify images (k-NN, SVM, decision tree, neural network)
UnsupervisedFind groups without labelsk-means clustering for segmentation
Deep learning (CNN)Neural network that learns features itselfClassification, segmentation (U-Net), denoising, compression
k-means segmentation in 4 steps
  1. Choose k (number of segments) and k starting centres
  2. Assign every pixel to the nearest centre (by intensity or colour)
  3. Recompute each centre as the mean of its pixels
  4. Repeat until the centres stop moving
Typical pipeline: image → preprocessing → segmentation → feature extraction → classifier (ML) → result. Training data teaches the model, test data checks it.
⚡Ready for Exam?Sab padh liya? Ab Quick Revision karo — definition, example aur diagram ek jagah!Quick Revision Karo →
⚡Quick Revision — Last Minute Exam Prep!
📌 How to use: Har topic mein pehle Definition, phir Example, phir Diagram hai.

🗜️ Chapter 1 — Image Compression

1. Compression Ratio and Redundancy
📖 Definition: Compression removes redundant data. CR = n1/n2, RD = 1 − 1/CR.
💡 Example: 10 MB → 2 MB: CR = 5 : 1, RD = 0.8.
CodingVariable-length codes (Huffman)
InterpixelPrediction, run-length, transform
PsychovisualQuantization (lossy)
2. Huffman Coding
📖 Definition: Shorter codes for more probable symbols, prefix-free.
💡 Example: Probabilities 0.4, 0.3, 0.1, 0.1, 0.06, 0.04 → Lavg = 2.2 bits (fixed code: 3 bits).
SymbolpCode length
a10.41
a20.32
a30.14
a40.14
a50.064
a60.044
3. Fidelity Criteria
📖 Definition: Objective (RMS, MSE, PSNR) and subjective rating measure image quality.
💡 Example: MSE = 25, 8-bit → PSNR ≈ 34.15 dB.
📐 Formulas
erms = [(1/MN) ΣΣ (f̂ − f)²]1/2
PSNR = 10 log10 [(L−1)² / MSE]
4. Compression Model
📖 Definition: Source encoder (mapper, quantizer, symbol encoder) plus channel encoder; decoder reverses it.
💡 Example: Quantizer is the only lossy block.
Source encoder: Mapper→Quantizer→Symbol encoder→Channel encoder→Channel
Channel decoder→Source decoder: Symbol decoder→Inverse mapper→f̂(x,y)
Top row: compression side. Bottom row: decompression side. The quantizer is the only lossy step (skipped in lossless compression).
5. Predictive Coding
📖 Definition: Code only the prediction error en = fn − f̂n.
💡 Example: 100, 102, 101, 103 → 100, +2, −1, +2.
fn→− prediction→error→encode
6. Transform Coding and JPEG
📖 Definition: Blocks → DCT → quantize → zigzag → run-length + Huffman.
💡 Example: Most energy sits in the top-left (low frequency) DCT coefficients.
015614152728
2471316262942
38121725304143
911182431404453
1019233239455254
2022333846515560
2134374750565961
3536484957586263
Zigzag scan order of an 8 × 8 block of DCT coefficients. 0 = DC (low frequency). The scan ends at 63 (highest frequency).
7. JPEG 2000
📖 Definition: Wavelet based, lossless and lossy in one system, uses EBCOT.
💡 Example: No blocking, only blur at high compression.
Colour transform→DWT→Quantization→EBCOT→Codestream

✂️ Chapter 2 — Image Segmentation

1. Points, Lines, Edges
📖 Definition: Discontinuities are found with masks: R = Σ wi zi.
💡 Example: Sobel on [10 10 10; 10 10 10; 100 100 100]: Gy = 360, a horizontal edge.
-1-1-1
-18-1
-1-1-1
Point
-1-1-1
222
-1-1-1
Horizontal line
-12-1
-12-1
-12-1
Vertical line
-1-12
-12-1
2-1-1
+45° line
2-1-1
-12-1
-1-12
−45° line
Intensity (ramp edge)1st derivative: peak2nd derivative: zero crossingedge
Edge detection uses the 1st derivative (look for a peak) or the 2nd derivative (look for a zero crossing).
2. Edge Operators
📖 Definition: Roberts, Prewitt, Sobel use the gradient. Laplacian and LoG use zero crossings. Canny gives thin edges.
💡 Example: M = √(Gx² + Gy²) ≈ |Gx| + |Gy|.
-101
-202
-101
Sobel Gx
-1-2-1
000
121
Sobel Gy
-101
-101
-101
Prewitt Gx
-1-1-1
000
111
Prewitt Gy
3. Edge Linking (Hough)
📖 Definition: Joins edge points into boundaries. Hough transform votes for lines in (a, b) space.
💡 Example: Points (1,1), (2,2), (3,3) meet at a = 1, b = 0.
Image space (x, y)Parameter space (a, b)peak at a = 1, b = 0 (y = x)
4. Thresholding
📖 Definition: g = 1 if f > T. Iterative: T = ½(m1 + m2). Otsu maximises between-class variance.
💡 Example: Pixels 10, 12, 11, 9, 200, 205, 198, 203 → T ≈ 106.
backgroundobjectTgray level →
A bimodal histogram has two peaks. The threshold T is placed in the valley between them.
5. Region Segmentation
📖 Definition: Region growing from seeds. Splitting and merging uses a quadtree.
💡 Example: Seed 10, rule |f − 10| ≤ 5 grows over the dark pixels only.
1012808285
1113798184
1011128386
910111287
89101112
📄Previous Year Questions

Previous Year Question Paper Not Available Yet

Unit 3 question papers are not available yet. If you have one, please share it through the contact page so it can be added for other students.