📖 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.
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 image
Exactly the same as the original
Close to the original, not identical
Compression ratio
Low (about 2 : 1 to 3 : 1)
High (10 : 1 or more)
Used for
Medical images, documents, text
Photos, video, web images
Examples
Huffman, LZW, RLE, PNG
JPEG, 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.
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).
Block
Job
Redundancy removed
Mapper
Converts pixels into a form better for compression (differences, transform coefficients, run lengths). Reversible
Interpixel
Quantizer
Reduces the accuracy of the mapper output. Irreversible, so it is skipped in lossless coding
Psychovisual
Symbol encoder
Assigns variable-length codes to the output
Coding
Channel encoder
Adds 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.
Merge
Probabilities combined
New probability
1
0.04 + 0.06
0.1
2
0.1 + 0.1
0.2
3
0.1 + 0.2
0.3
4
0.3 + 0.3
0.6
5
0.4 + 0.6
1.0
Symbol
Probability
Huffman code
Length
a1
0.4
0
1
a2
0.3
10
2
a3
0.1
1110
4
a4
0.1
1111
4
a5
0.06
1101
4
a6
0.04
1100
4
📐 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
Method
Idea
Example
Run-length coding (RLE)
Store (value, run length) instead of repeating values
Codes the whole message as one number between 0 and 1, by repeatedly narrowing an interval by symbol probabilities
Gets closer to entropy than Huffman, no whole-bit limit per symbol
LZW (dictionary)
Builds a dictionary of repeated patterns while reading, and outputs dictionary indexes
Used in GIF, TIFF
Bit-plane coding
Split 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.
💡 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.
n
Original f
Error e
Quantized ė (step 4)
Reconstructed
0
100
—
—
100
1
104
4
4
104
2
109
5
4
108
3
108
0
0
108
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.
0
1
5
6
14
15
27
28
2
4
7
13
16
26
29
42
3
8
12
17
25
30
41
43
9
11
18
24
31
40
44
53
10
19
23
32
39
45
52
54
20
22
33
38
46
51
55
60
21
34
37
47
50
56
59
61
35
36
48
49
57
58
62
63
Zigzag scan order of an 8 × 8 block of DCT coefficients. 0 = DC (low frequency). The scan ends at 63 (highest frequency).
Zonal coding
Threshold coding
Idea
Keep a fixed zone of low-frequency coefficients
Keep coefficients whose magnitude is above a threshold
Zone
Same for all blocks
Changes 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.
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
The regions together cover the whole image: ∪ Ri = R
Each region Ri is a connected set
Regions do not overlap: Ri ∩ Rj = ∅ for i ≠ j
Pixels of a region share a property: Q(Ri) = TRUE
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
-1
8
-1
-1
-1
-1
Point
-1
-1
-1
2
2
2
-1
-1
-1
Horizontal line
-1
2
-1
-1
2
-1
-1
2
-1
Vertical line
-1
-1
2
-1
2
-1
2
-1
-1
+45° line
2
-1
-1
-1
2
-1
-1
-1
2
−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.
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
-1
0
1
-2
0
2
-1
0
1
Sobel Gx
-1
-2
-1
0
0
0
1
2
1
Sobel Gy
-1
0
1
-1
0
1
-1
0
1
Prewitt Gx
-1
-1
-1
0
0
0
1
1
1
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
Detector
Idea
Remark
Laplacian ∇²f
2nd derivative, zero crossing marks the edge
Very sensitive to noise, gives double edges, no direction
LoG (Marr–Hildreth)
Smooth with a Gaussian, then Laplacian, then find zero crossings
📖 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.
💡 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.
A bimodal histogram has two peaks. The threshold T is placed in the valley between them.
Basic global thresholding (iterative)
Choose an initial threshold T (for example the mean of all pixels)
Split pixels into G1 (> T) and G2 (≤ T)
Find the mean m1 of G1 and m2 of G2
New T = ½ (m1 + m2)
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.
Type
Idea
Global
One T for the whole image. Works for uniform lighting and bimodal histograms
Otsu's method
Chooses T that maximises the between-class variance σB² = ω1ω2(μ1 − μ2)²
Adaptive (local)
Different T for each small region. Handles uneven illumination
Multiple thresholds
T1, 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
Pick one or more seed pixels
Add a neighbouring pixel if it satisfies the similarity rule (e.g. |intensity − seed| ≤ T)
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-based
Thresholding
Region-based
Looks at
Sudden changes
Gray-level histogram
Similar neighbours
Strength
Finds boundaries
Simple, fast
Closed, connected regions
Weakness
Gaps, noise
Fails with uneven light
Depends 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).
Choose k (number of segments) and k starting centres
Assign every pixel to the nearest centre (by intensity or colour)
Recompute each centre as the mean of its pixels
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.