Huffman Image Compression

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/23

flashcard set

Earn XP

Description and Tags

🎯 Objective: Compress a color image using DCT + Huffman encoding, then reconstruct it. We apply the process to each RGB channel separately.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

Q: Why convert the image to double after reading it?

A: Because DCT requires floating-point values for accurate transformation.

2
New cards

Q: Why not convert this image to grayscale?

A: Because in this version, we want to compress and reconstruct the full color image using its R, G, B channels separately.

3
New cards

Q: What does img(:,:,c) mean?

A: It selects the c-th color channel (R, G, or B) from the 3D RGB image.

4
New cards

Q: Why apply DCT to each channel?

A: To convert the image into the frequency domain where most energy is concentrated in fewer coefficients, making compression more effective.

5
New cards

Q: Why do we round the DCT coefficients?

A: To reduce precision, increasing repeated values which improves Huffman compression.

6
New cards

Q: Why do we flatten the DCT matrix before encoding?

A: Huffman encoding operates on 1D sequences, so we reshape the 2D matrix into a vector.

7
New cards

Q: What is the purpose of huffmandict() and huffmanenco()?

A: They create a codebook and compress the data based on symbol frequencies.

8
New cards

Q: What is huffmandeco() used for?

A: To decompress the encoded bitstream using the same Huffman dictionary.

9
New cards

Q: Why do we reshape the decoded data?

A: To return it to its original 2D matrix form for inverse DCT.

10
New cards

Q: What does idct2() do?

A: It reconstructs the image from its DCT coefficients back to pixel values.

11
New cards

Q: Why do we cast the final image to uint8 before displaying?

A: Because image pixel values must be in the range 0–255 and uint8 ensures proper display format.

12
New cards

Q: How is compression ratio calculated?

A: By dividing the total original bits by the total compressed bits.

13
New cards

Q: What are the two types of compression used here?

A:

  1. Lossy: DCT + Rounding

  2. Lossless: Huffman Encoding

14
New cards

Q: Why do we flatten the DCT matrix?

A: Huffman encoding requires a 1D sequence of symbols to compress.

15
New cards

Q: What are "symbols" in Huffman encoding?

A: The unique values (integers) in the data that will each get a unique binary code.

16
New cards

Q: Why do we calculate symbol probabilities?

A: So that more frequent values can be assigned shorter Huffman codes.

17
New cards

Q: What does huffmandict() do?

A: It creates a dictionary that maps each symbol to a Huffman binary code based on frequency.

18
New cards

Q: What does huffmanenco() do?

A: It encodes the input vector into a compressed bitstream using the Huffman dictionary.

19
New cards

Q: Why do we store the dictionary and original size with the encoded data?

A: So we can properly decode and reshape the image during reconstruction.

20
New cards

Q: What does huffmandeco() do?

A: It decodes a compressed Huffman bitstream back into its original sequence of symbols (numbers).

21
New cards

Q: What inputs are needed for Huffman decoding?

A: The compressed bitstream and the Huffman dictionary used for encoding.

22
New cards

Q: Why do we use reshape() after decoding?

A: Because the DCT data was originally a 2D matrix and we need to restore its shape before applying inverse DCT.

23
New cards

Q: What does size(channel) do in reshape()?

A: It ensures we reshape the decoded data to exactly match the original image dimensions.

24
New cards