Total Pageviews

Thursday, September 10, 2026

2-D DCT Value Generator

2-D DCT Value Generator
Generate a random 8 × 8 matrix and calculate only its DCT values step by step

šŸ“ DCT Formula

D(u,v) = 1/4 × C(u) × C(v) × Ī£ Ī£ f(x,y) cos[(2x+1)uĻ€/16] cos[(2y+1)vĻ€/16]
C(0) = 1/√2     C(k) = 1 for k > 0

Step 1 — Random 8 × 8 Matrix

Step 2 — DCT Calculation

Click ▶ NEXT DCT VALUE to calculate the DCT coefficients one by one.
DCT Values Calculated: 0 / 64

Step 3 — DCT Values

© B.K.PAUL • DCT Educational Visualization

šŸ” 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.

✅ After decompression, the original image can be reconstructed exactly.
Original Image → Lossless Encoder → Compressed Data → Lossless Decoder → Original Image

šŸ“¤ 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

Original image

8-bit Grayscale Image

šŸ“ 3. Grayscale Image Size

0 Width
0 Height
0 Total Pixels
8 bits Bits / Pixel
Parameter Value
Dimensions -
Total Pixels -
Raw Grayscale Size -
PNG Lossless Size -

🧮 Mathematical Calculation

šŸ“Š 4. Lossless Compression Result

- Original Size
- PNG Size
- Compression Ratio
- Size Reduction
Measurement Result
Original File -
Lossless PNG -
Compression Ratio -
Size Reduction -
Pixel Verification -
⬇️ Download Lossless PNG

šŸ” 5. Lossless Pixel Verification

In lossless compression, decompression must reproduce the same pixel values.

Original Pixel Value = Reconstructed Pixel Value

Therefore:
Error = 0

MSE = 0

šŸ”¢ 6. Run Length Encoding — RLE

RLE replaces consecutive repeated values with a value and its repetition count.

Original: AAAAABBBCCAAAA

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.

High Frequency Symbol → Short Code

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.

Input Pattern → Dictionary Search → Dictionary Code → Compressed Data

šŸ”„ 9. Lossless Image Compression Pipeline

Image
Pixel Data
Redundancy
RLE / LZW
Huffman
Compressed

šŸ”Ž 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

šŸ–¼️ 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.

Key idea: A smaller amount of data is stored, but the reconstructed image may not be exactly identical to the original image.
Original Image → Transformation → Quantization → Encoding → Compressed Image

šŸ“¤ 1. Upload Image

Upload a photograph or other image to demonstrate lossy JPEG compression.



šŸ–¼️ 2. Original vs Compressed Image

Original Image

Original image

Compressed JPEG

Compressed image

šŸŽš️ 3. JPEG Quality Control

Move the slider to change JPEG compression quality.

80%

Higher quality → larger file → less information loss
Lower quality → smaller file → more information loss

šŸ“Š 4. Compression Results

- Original Size
- Compressed Size
- Compression Ratio
- Size Reduction
- MSE
- PSNR
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

F(u,v) = 1/4 C(u)C(v) Σ Σ f(x,y) cos[(2x+1)uπ/16] cos[(2y+1)vπ/16]

DCT transforms pixel information from the spatial domain into the frequency domain.

Step 2 — Quantization

Q(u,v) = round(F(u,v) / T(u,v))

This is the main lossy operation in JPEG.

Step 3 — Encoding

Quantized Coefficients → Zig-Zag Scan → Run Length Encoding → Huffman Coding

šŸŽÆ 6. Quantization Example

Suppose a DCT coefficient is:

F(u,v) = 137

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) ≈ 14 × 10

F'(u,v) ≈ 140
Original coefficient = 137
Reconstructed coefficient ≈ 140

Therefore, some information has been lost.

šŸ“ 7. Measuring Image Quality

Mean Squared Error — MSE

MSE = (1/N) Ī£ [I(x,y) − K(x,y)]²

Lower MSE means the compressed image is closer to the original image.

Peak Signal-to-Noise Ratio — PSNR

PSNR = 10 log₁₀(MAX² / MSE)

For an 8-bit image:

MAX = 255
Higher PSNR generally means better reconstructed image quality.

šŸ”„ 8. JPEG Lossy Compression Pipeline

RGB Image
YCbCr
8×8 Blocks
DCT
Quantization
Zig-Zag
RLE
Huffman
JPEG

⚖️ 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.

šŸ–¼️ 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

No image selected.

2️⃣ Image for Compression Study

šŸ–¼️ Original Image

Uploaded 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.

CR = Original Size / Compressed Size

Percentage reduction:

Reduction = [(Original − Compressed) / Original] × 100%
Click Calculate Ratio.

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.

AAAAABBBCCAAAA
becomes:
A5 B3 C2 A4

šŸ”¬ Interactive RLE Demonstration

Enter a sequence and click Compress.

7️⃣ Entropy and Image Compression

Entropy measures the average information contained in the image intensity distribution.

H = −Ī£ pįµ¢ log₂(pįµ¢)

For an 8-bit grayscale image:

0 ≤ H ≤ 8 bits/pixel
Important: Lower statistical redundancy generally provides less opportunity for lossless compression, while predictable/repetitive data is often more compressible. Entropy provides a theoretical lower bound for average lossless coding length under the appropriate source model.

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.

F(u,v) = (1/4) C(u)C(v) ΣΣ f(x,y) cos[(2x+1)uĻ€/16] cos[(2y+1)vĻ€/16]
where:
f(x,y)

Original 8×8 image block.

F(u,v)

DCT frequency coefficient.

u,v

Frequency coordinates.

C(u), C(v)

Normalization factors.

8×8 Image Block

The upper-left coefficient is called the DC coefficient. Other coefficients represent increasing spatial frequencies.

9️⃣ Quantization

Quantization reduces the precision of DCT coefficients. This is the major stage responsible for information loss in typical JPEG compression.

Q(u,v) = round[F(u,v) / Qtable(u,v)]

Larger quantization values produce stronger compression but usually lower image quality.

Small Quantization

More coefficients are retained.

Higher quality → Larger file

Large 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
Click Start JPEG Animation.

1️⃣1️⃣ Measuring Compression Quality

Mean Squared Error — MSE

MSE = (1/MN) ΣΣ [I(i,j) − K(i,j)]²

where I is the original image and K is the reconstructed image.

Peak Signal-to-Noise Ratio — PSNR

PSNR = 10 log₁₀(MAX²/MSE)

For an 8-bit image:

MAX = 255
Generally: Lower MSE means less pixel-wise error. Higher PSNR generally indicates better reconstruction quality.

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

Image → Remove Redundancy → Transform / Predict → Quantize → Entropy Coding → Compressed Image

Important Formulas

Compression Ratio = Original Size / Compressed Size
H = −Ī£pįµ¢log₂(pįµ¢)
MSE = (1/MN)ΣΣ[I(i,j)−K(i,j)]²
PSNR = 10log₁₀(255²/MSE)

šŸ“” 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.

The average number of bits required to represent a source symbol cannot be smaller than the entropy of the source.
H(X) ≤ L

where:

  • H(X) = entropy of the source
  • L = average codeword length

2️⃣ Statement of Shannon's First Theorem

H(X) ≤ L < H(X) + 1

For a discrete memoryless source and a suitable binary prefix code, there exists a code whose average codeword length satisfies:

H(X) ≤ L < H(X)+1
Meaning: Entropy represents the theoretical minimum average number of bits required per source symbol for lossless coding.

3️⃣ Entropy of a Source

Suppose a source produces symbols:

X = {x₁,x₂,...,xā‚™}

with probabilities:

P(X) = {p₁,p₂,...,pā‚™}

The entropy is:

H(X) = −Ī£ pįµ¢ log₂(pįµ¢)

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įµ¢.

L = Σ pᵢ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
L = 0.50 + 0.50 + 0.375 + 0.375
L = 1.75 bits/symbol

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

H = −[0.5log₂0.5 +0.25log₂0.25 +0.125log₂0.125 +0.125log₂0.125]
H = 0.5 + 0.5 + 0.375 + 0.375
H = 1.75 bits/symbol

Step 2 — Calculate Average Code Length

L = Σpᵢlᵢ
L = (0.5)(1)+(0.25)(2)+(0.125)(3)+(0.125)(3)
L = 1.75 bits/symbol

Step 3 — Verify Shannon's Theorem

H ≤ L
1.75 ≤ 1.75

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
Key idea: The more probable a symbol is, the shorter its code should generally be.

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.

H(X) ≤ LHuffman < H(X)+1

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

Click Calculate.

1️⃣1️⃣ Verify the Shannon Bound

H(X) ≤ L

Suppose:

H(X)=1.75

and

L=1.75

Then:

1.75 ≤ 1.75

The code is optimal with respect to the entropy bound.

For a general code, if:

H(X) ≤ L < H(X)+1

the average code length is within one bit per symbol of the theoretical entropy limit.

1️⃣2️⃣ Animated Concept

šŸ“” Source
Symbols
šŸ“Š Probability
pįµ¢
🧮 Entropy
H(X)
šŸ”¤ Codewords
lįµ¢
šŸ“ Average
L
✅ H ≤ L

Click Start Animation

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: H(X) = −Ī£pįµ¢log₂(pįµ¢)
Average Code Length: L = Σpᵢlᵢ
Shannon's Bound: H(X) ≤ L
Practical Single-Symbol Bound: H(X) ≤ L < H(X)+1
šŸ“Œ Remember:

Entropy is the fundamental lower bound on the average number of bits per source symbol required by lossless source coding.

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.

H = − Ī£ pįµ¢ log₂(pįµ¢)

šŸ”µ 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.

Hmax = log₂(256) = 8 bits

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.

pįµ¢ = nįµ¢ / N

The information associated with gray level i is:

I(i) = −log₂(pįµ¢)

The average information is obtained by multiplying each information value by its probability:

H = Σ pᵢ I(i)

Therefore:

H = −Ī£ pįµ¢ log₂(pįµ¢)

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:

H = −[0.25log₂(0.25) + 0.25log₂(0.25) + 0.25log₂(0.25) + 0.25log₂(0.25)]

Since:

log₂(0.25) = −2

Therefore:

H = −[4 × 0.25 × (−2)]
H = 2 bits/pixel

4️⃣ Entropy Calculation — Interactive

Enter probabilities for four intensity groups. The probabilities should approximately add up to 1.

Enter probabilities and click Calculate Entropy.

5️⃣ Histogram and Entropy

The histogram represents the distribution of intensity values. Entropy is calculated from the normalized histogram.

Important: A histogram alone does not directly give entropy. First convert histogram frequencies into probabilities:

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:

p(128) = 1
Therefore:
H = −1 × log₂(1)
H = 0 bits/pixel
There is no uncertainty because we already know that every pixel has the same intensity.

8️⃣ Maximum Entropy

Maximum entropy occurs when all possible intensity values are equally likely.

For an 8-bit grayscale image:

pįµ¢ = 1/256
Therefore:
H = −Ī£(1/256)log₂(1/256)
Since there are 256 terms:
H = −256 × (1/256) × log₂(1/256)
H = log₂(256)
H = 8 bits/pixel

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:

p₁ = 0.5,   p₂ = 0.5
H = −[0.5log₂(0.5)+0.5log₂(0.5)]
H = 1 bit/pixel

Example 2 — Unequal probabilities

p₁ = 0.8,   p₂ = 0.2
H = −[0.8log₂(0.8)+0.2log₂(0.2)]
H ≈ 0.722 bits/pixel

Because one intensity dominates, the entropy is lower than the 50%-50% case.

Example 3 — Four equally probable levels

p₁=p₂=p₃=p₄=0.25
H = 2 bits/pixel

1️⃣1️⃣ Entropy Animation

The following animation shows how image pixels are converted into probabilities and finally into entropy.

šŸ–¼️ Image
Pixels
šŸ“Š Histogram
nįµ¢
šŸ“ Probability
pįµ¢ = nįµ¢/N
🧮 Information
−log₂(pįµ¢)
šŸ“ˆ Entropy
H
Click Start Animation.

1️⃣2️⃣ Important Formula Summary

Probability:   pįµ¢ = nįµ¢/N
Information:   I(i) = −log₂(pįµ¢)
Image Entropy:   H = −Ī£ pįµ¢log₂(pįµ¢)
Maximum entropy:   Hmax = log₂(L)
8-bit grayscale:   Hmax = log₂(256) = 8 bits/pixel

šŸŽÆ Concept in One Line

šŸ–¼️ Image → šŸ“Š Histogram → šŸ“ Probability → 🧮 Information → šŸ“ˆ Entropy

Higher entropy generally means a more varied and information-rich intensity distribution, while lower entropy indicates a more predictable or uniform distribution.