Bijan Krishna Paul
VILL- DEBANDI, AMTA, HOWRAH PIN-711410 Phone-9836357266
Total Pageviews
Thursday, September 10, 2026
2-D DCT Value Generator
š Lossless Image Compression
š Lossless Image Compression
Interactive Image Processing Lab • PNG • RLE • Huffman • LZW
š What is Lossless Compression?
Lossless compression reduces the size of an image without permanently removing image information.
š¤ 1. Upload an Image
Upload an image to analyse its dimensions, raw grayscale size and PNG lossless representation.
š¼️ 2. Original and Grayscale Image
Original Image
8-bit Grayscale Image
š 3. Grayscale Image Size
| Parameter | Value |
|---|---|
| Dimensions | - |
| Total Pixels | - |
| Raw Grayscale Size | - |
| PNG Lossless Size | - |
š§® Mathematical Calculation
š 4. Lossless Compression Result
| Measurement | Result |
|---|---|
| Original File | - |
| Lossless PNG | - |
| Compression Ratio | - |
| Size Reduction | - |
| Pixel Verification | - |
š 5. Lossless Pixel Verification
In lossless compression, decompression must reproduce the same pixel values.
Therefore:
Error = 0
MSE = 0
š¢ 6. Run Length Encoding — RLE
RLE replaces consecutive repeated values with a value and its repetition count.
RLE: A5 B3 C2 A4
š³ 7. Huffman Coding
Huffman coding assigns shorter binary codes to frequently occurring symbols and longer codes to less frequent symbols.
Low Frequency Symbol → Long Code
| Symbol | Frequency | Example Code |
|---|---|---|
| A | 50% | 0 |
| B | 25% | 10 |
| C | 15% | 110 |
| D | 10% | 111 |
š 8. LZW Compression
LZW is a dictionary-based lossless compression technique. Repeated patterns are represented by dictionary codes.
š 9. Lossless Image Compression Pipeline
š 10. Redundancy in Images
| Redundancy | Meaning | Technique |
|---|---|---|
| Coding Redundancy | Inefficient representation of symbols | Huffman Coding |
| Spatial Redundancy | Neighbouring pixels are similar | RLE / Prediction |
| Statistical Redundancy | Some values occur more frequently | Entropy Coding |
⚖️ 11. Lossless vs Lossy
| Feature | Lossless | Lossy |
|---|---|---|
| Information Loss | ❌ No | ✅ Yes |
| Exact Recovery | ✅ Yes | ❌ No |
| Compression | Moderate | High |
| Quality | Original | May decrease |
| Examples | PNG, GIF, RLE, LZW | JPEG |
š” 12. Applications
- Medical images
- Technical drawings
- Satellite imagery
- Documents and scanned images
- Graphics and logos
- Archiving
- Scientific image storage
B.K.PAUL Bhairab Ganguly College
š¼️ Lossy Image Compression
š¼️ Lossy Image Compression
Interactive JPEG Compression • DCT • Quantization • MSE • PSNR
š What is Lossy Compression?
Lossy compression reduces the size of an image by permanently removing some information that is less important to human visual perception.
š¤ 1. Upload Image
Upload a photograph or other image to demonstrate lossy JPEG compression.
š¼️ 2. Original vs Compressed Image
Original Image
Compressed JPEG
š️ 3. JPEG Quality Control
Move the slider to change JPEG compression quality.
Higher quality → larger file → less information loss
Lower quality → smaller file → more information loss
š 4. Compression Results
| Parameter | Result |
|---|---|
| Image Dimensions | - |
| JPEG Quality | - |
| Original File Size | - |
| Compressed File Size | - |
| Compression Ratio | - |
| Size Reduction | - |
| MSE | - |
| PSNR | - |
⬇️ Download Compressed JPEG
š§® 5. Mathematics of Lossy Compression
Step 1 — DCT
DCT transforms pixel information from the spatial domain into the frequency domain.
Step 2 — Quantization
This is the main lossy operation in JPEG.
Step 3 — Encoding
šÆ 6. Quantization Example
Suppose a DCT coefficient is:
T(u,v) = 10
Q(u,v) = round(137 / 10)
Q(u,v) = round(13.7)
Q(u,v) = 14
During reconstruction:
F'(u,v) ≈ 140
Reconstructed coefficient ≈ 140
Therefore, some information has been lost.
š 7. Measuring Image Quality
Mean Squared Error — MSE
Lower MSE means the compressed image is closer to the original image.
Peak Signal-to-Noise Ratio — PSNR
For an 8-bit image:
š 8. JPEG Lossy Compression Pipeline
⚖️ 9. Lossless vs Lossy Compression
| Feature | Lossless | Lossy |
|---|---|---|
| Information Loss | No | Yes |
| Original Recovery | Exact | Not exact |
| File Size | Moderate | Usually smaller |
| Quality | Original quality | Depends on compression |
| Examples | PNG, RLE, Huffman | JPEG |
✅ 10. Advantages of Lossy Compression
- Significantly reduces image file size.
- Reduces storage requirements.
- Reduces network transmission time.
- Useful for websites and online applications.
- JPEG provides adjustable quality levels.
⚠️ Disadvantages
- Some information is permanently removed.
- Repeated compression can reduce quality.
- Very high compression can produce visible artifacts.
- The original image cannot be reconstructed exactly.
B.K.PAUL Bhairab Ganguly College
š¼️ Image Compression Techniques
š¼️ Image Compression Techniques
Learn how digital images are compressed using mathematical and information-theoretic techniques such as RLE, Huffman Coding, DCT, Quantization and JPEG.
1️⃣ Upload Your Image
2️⃣ Image for Compression Study
š¼️ Original Image
Upload an image to begin.
⚫ Grayscale Version
3️⃣ What is Image Compression?
Image compression reduces the number of bits required to represent an image while attempting to preserve the important visual information.
š¢ Lossless Compression
The reconstructed image is exactly identical to the original image. No information is permanently lost.
Examples: RLE, Huffman, LZW, PNG.
š Lossy Compression
Some information is discarded to obtain a much smaller file. The reconstructed image is usually an approximation.
Example: JPEG.
šµ Redundancy
Compression removes different forms of redundancy:
- Spatial redundancy
- Statistical redundancy
- Psychovisual redundancy
š£ Main Goal
Reduce storage and transmission requirements while maintaining acceptable image quality.
4️⃣ Major Compression Techniques
| Technique | Type | Main Idea | Typical Use |
|---|---|---|---|
| RLE | Lossless | Encode repeated values | Simple images |
| Huffman | Lossless | Short codes for frequent symbols | JPEG / general coding |
| LZW | Lossless | Dictionary-based coding | GIF / TIFF |
| DPCM | Predictive | Encode prediction error | Image signals |
| DCT | Transform | Convert spatial data to frequency coefficients | JPEG |
| DWT | Transform | Wavelet decomposition | JPEG 2000 |
| Quantization | Lossy | Reduce coefficient precision | JPEG |
5️⃣ Compression Ratio
Compression ratio compares the original size with the compressed size.
Percentage reduction:
6️⃣ Run-Length Encoding (RLE)
RLE is a simple lossless compression technique. Instead of storing every repeated pixel separately, it stores the value and the number of consecutive repetitions.
š¬ Interactive RLE Demonstration
7️⃣ Entropy and Image Compression
Entropy measures the average information contained in the image intensity distribution.
For an 8-bit grayscale image:
8️⃣ DCT — Discrete Cosine Transform
JPEG divides an image into 8×8 blocks and applies the Discrete Cosine Transform to represent spatial intensity variations as frequency coefficients.
Original 8×8 image block.
DCT frequency coefficient.
Frequency coordinates.
Normalization factors.
8×8 Image Block
9️⃣ Quantization
Quantization reduces the precision of DCT coefficients. This is the major stage responsible for information loss in typical JPEG compression.
Larger quantization values produce stronger compression but usually lower image quality.
Small Quantization
More coefficients are retained.
Higher quality → Larger fileLarge Quantization
More coefficients become zero or smaller.
Lower quality → Smaller fileš JPEG Compression Pipeline
Image
RGB → YCbCr
8×8 Blocks
DCT
Quantization
Zig-Zag
RLE
Huffman
Compressed
1️⃣1️⃣ Measuring Compression Quality
Mean Squared Error — MSE
where I is the original image and K is the reconstructed image.
Peak Signal-to-Noise Ratio — PSNR
For an 8-bit image:
1️⃣2️⃣ Lossless vs Lossy Compression
| Feature | Lossless | Lossy |
|---|---|---|
| Information loss | No | Yes |
| Reconstruction | Exactly original | Approximation |
| Compression ratio | Usually lower | Usually higher |
| Quality degradation | None | Possible |
| Examples | PNG, RLE, Huffman, LZW | JPEG |
| Best suited for | Medical/technical graphics, text-like images | Photographs and natural scenes |
1️⃣3️⃣ Three Types of Redundancy
1. Statistical Redundancy
Some symbols occur much more frequently than others. Huffman coding can exploit this redundancy.
2. Spatial Redundancy
Neighboring pixels often have similar values. Predictive and transform techniques can exploit this property.
3. Psychovisual Redundancy
Human vision does not perceive all image information equally. Lossy techniques can discard some less perceptually important information.
1️⃣4️⃣ Applications
š± Mobile Applications
Reducing image size saves storage and network bandwidth.
š Web Images
Compressed images improve page loading and reduce bandwidth usage.
š°️ Satellite Images
Compression reduces the amount of data that must be transmitted.
š„ Medical Imaging
Lossless methods are particularly important when exact pixel information must be preserved.
š¹ Video Processing
Image compression principles form an important foundation for video compression systems.
☁️ Cloud Storage
Compression can reduce storage requirements for large image collections.
šÆ Complete Compression Flow
Important Formulas
B.K.PAUL Bhairab Ganguly College
š” Shannon's First Theorem
š” Shannon's First Theorem
Noiseless Coding Theorem — Fundamental Limit of Lossless Source Coding
1️⃣ What is Shannon's First Theorem?
Shannon's First Theorem is also known as the Noiseless Coding Theorem or Shannon's Source Coding Theorem.
It describes the theoretical limit for lossless compression of data generated by an information source.
where:
- H(X) = entropy of the source
- L = average codeword length
2️⃣ Statement of Shannon's First Theorem
For a discrete memoryless source and a suitable binary prefix code, there exists a code whose average codeword length satisfies:
3️⃣ Entropy of a Source
Suppose a source produces symbols:
with probabilities:
The entropy is:
where:
- pįµ¢ is the probability of symbol xįµ¢
- logarithm is base 2
- entropy is measured in bits/symbol
4️⃣ Average Codeword Length
Suppose each symbol xįµ¢ is represented by a codeword of length lįµ¢.
Thus the average number of bits per source symbol is the probability weighted average of codeword lengths.
| Symbol | Probability | Code | Length | pįµ¢lįµ¢ |
|---|---|---|---|---|
| A | 0.50 | 0 | 1 | 0.50 |
| B | 0.25 | 10 | 2 | 0.50 |
| C | 0.125 | 110 | 3 | 0.375 |
| D | 0.125 | 111 | 3 | 0.375 |
5️⃣ Complete Mathematical Example
Example: Four-Symbol Source
| Symbol | Probability | Code | Length |
|---|---|---|---|
| A | 0.50 | 0 | 1 |
| B | 0.25 | 10 | 2 |
| C | 0.125 | 110 | 3 |
| D | 0.125 | 111 | 3 |
Step 1 — Calculate Entropy
Step 2 — Calculate Average Code Length
Step 3 — Verify Shannon's Theorem
Therefore, the code reaches the entropy bound exactly.
6️⃣ Why Can't We Go Below Entropy?
š Information Limit
Entropy represents the average information generated by the source. Lossless coding cannot represent that information using fewer average bits than its information content.
š️ Compression Limit
A compression algorithm may reduce the average code length, but it cannot continuously beat the entropy limit for a source without losing information.
š¾ Data Storage
Entropy helps estimate how efficiently source data can theoretically be stored.
š” Communication
It provides a fundamental limit for lossless transmission of source information.
7️⃣ Shannon-Fano Coding Connection
Shannon-Fano coding assigns shorter codes to more probable symbols and longer codes to less probable symbols.
Example
| Symbol | Probability | Possible Code |
|---|---|---|
| A | 0.40 | 0 |
| B | 0.30 | 10 |
| C | 0.20 | 110 |
| D | 0.10 | 111 |
8️⃣ Huffman Coding and Shannon's Theorem
Huffman coding is another important lossless source coding technique. It constructs a prefix code with minimum average codeword length among binary prefix codes for a given symbol distribution.
For some probability distributions, Huffman coding can achieve entropy exactly. For others, it produces an average length slightly above entropy.
9️⃣ Ten Quick Numerical Examples
| No. | Source Probabilities | Entropy | Observation |
|---|---|---|---|
| 1 | 0.5, 0.5 | 1.000 | Maximum for 2 symbols |
| 2 | 0.8, 0.2 | 0.722 | Biased source |
| 3 | 0.9, 0.1 | 0.469 | Highly biased |
| 4 | 0.25,0.25,0.25,0.25 | 2.000 | Uniform 4-symbol source |
| 5 | 0.5,0.25,0.125,0.125 | 1.750 | Non-uniform source |
| 6 | 0.4,0.3,0.2,0.1 | 1.846 | Four-symbol source |
| 7 | 0.7,0.1,0.1,0.1 | 1.357 | One dominant symbol |
| 8 | 0.6,0.2,0.1,0.1 | 1.571 | Moderate uncertainty |
| 9 | 0.5,0.3,0.2 | 1.485 | Three-symbol source |
| 10 | 0.25,0.5,0.125,0.125 | 1.750 | Reordered probabilities |
š Interactive Shannon Theorem Calculator
Enter four probabilities and four codeword lengths. The probabilities should add up to approximately 1.
Codeword Lengths
1️⃣1️⃣ Verify the Shannon Bound
Suppose:
and
Then:
The code is optimal with respect to the entropy bound.
For a general code, if:
the average code length is within one bit per symbol of the theoretical entropy limit.
1️⃣2️⃣ Animated Concept
Symbols
pįµ¢
H(X)
lįµ¢
L
1️⃣3️⃣ Applications
š️ Data Compression
Used to understand the fundamental limit of lossless compression.
š File Compression
The principle is relevant to compression techniques such as Huffman coding and related statistical coding methods.
š” Communication
Provides the source-coding limit before considering transmission noise.
š¾ Storage
Helps determine how efficiently information can theoretically be represented.
1️⃣4️⃣ Formula Summary
Entropy is the fundamental lower bound on the average number of bits per source symbol required by lossless source coding.
B.K.PAUL Bhairab Ganguly College
Entropy in Image Processing
š¼️ Entropy in Image Processing
Measuring the information, randomness and complexity present in an image using probability and information theory.
1️⃣ What is Image Entropy?
Image entropy is a numerical measure of the amount of information or uncertainty contained in an image.
It is calculated from the probability distribution of the image's intensity values.
šµ Low Entropy
Most pixels have similar intensity values. The image is relatively uniform.
Example: A plain white wall.
š¢ High Entropy
Many different intensity values occur with significant probabilities.
Example: A detailed natural scene.
š£ Entropy Unit
When logarithm base 2 is used, entropy is measured in:
bits/pixel
š 8-bit Image
An 8-bit grayscale image contains 256 possible intensity values.
2️⃣ Mathematical Derivation
Suppose an image contains N pixels and has L possible gray levels. Let nįµ¢ be the number of pixels having gray level i.
The information associated with gray level i is:
The average information is obtained by multiplying each information value by its probability:
Therefore:
3️⃣ Worked Example — Simple Image
Consider a small grayscale image whose pixels contain four intensity levels.
| Gray Level | Number of Pixels | Probability pįµ¢ |
|---|---|---|
| 0 | 4 | 4/16 = 0.25 |
| 85 | 4 | 4/16 = 0.25 |
| 170 | 4 | 4/16 = 0.25 |
| 255 | 4 | 4/16 = 0.25 |
Therefore:
Since:
Therefore:
4️⃣ Entropy Calculation — Interactive
Enter probabilities for four intensity groups. The probabilities should approximately add up to 1.
5️⃣ Histogram and Entropy
The histogram represents the distribution of intensity values. Entropy is calculated from the normalized histogram.
pįµ¢ = nįµ¢ / N
Then calculate:
H = −Ī£ pįµ¢ log₂(pįµ¢)
6️⃣ Low Entropy vs High Entropy
| Property | Low Entropy | High Entropy |
|---|---|---|
| Intensity variation | Low | High |
| Image complexity | Low | High |
| Uniformity | High | Low |
| Information content | Low | High |
| Typical histogram | Concentrated | Spread out |
| Example | Plain background | Detailed texture |
7️⃣ Entropy of a Uniform 8-bit Image
For a completely uniform image, suppose every pixel has intensity 128.
Then:
8️⃣ Maximum Entropy
Maximum entropy occurs when all possible intensity values are equally likely.
For an 8-bit grayscale image:
9️⃣ Entropy in Image Processing — Applications
š Image Segmentation
Entropy can help identify regions containing different levels of texture and information.
š️ Image Compression
Entropy gives an estimate of the theoretical lower bound of average bits needed to represent image information.
š§© Texture Analysis
Highly textured regions generally contain greater intensity variation and may have higher entropy.
š„️ Image Quality Analysis
Entropy can be used as one statistical feature when comparing images or image-processing results.
š Image Security
Entropy is commonly considered when evaluating randomness in image-encryption results.
š¤ Computer Vision
Entropy can be used as a feature for classification and region analysis.
š Important Numerical Examples
Example 1 — Two intensity levels
Suppose:
Example 2 — Unequal probabilities
Because one intensity dominates, the entropy is lower than the 50%-50% case.
Example 3 — Four equally probable levels
1️⃣1️⃣ Entropy Animation
The following animation shows how image pixels are converted into probabilities and finally into entropy.
Pixels
nįµ¢
pįµ¢ = nįµ¢/N
−log₂(pįµ¢)
H
1️⃣2️⃣ Important Formula Summary
šÆ Concept in One Line
Higher entropy generally means a more varied and information-rich intensity distribution, while lower entropy indicates a more predictable or uniform distribution.
B.K.PAUL Bhairab Ganguly College