Total Pageviews

Thursday, September 10, 2026

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

No comments:

Post a Comment