im trying huffman encoding in matlab and reached the part where i get a table with huffman codes, what's next ?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, so i have being trying to implement huffman encoding for an image compression project i got, and in my code im able to reach where i get a table of each symbol and it's code such as the one im posting below, but im not quite sure what i do after this, should i replace each pixel in my image with the new code as a string, or should i combine multiple codes and store each 8 bits on it own, or what ? since you cant save a value as binary in matlab im not quite sure where to go from this
Symbol Probablity Code
1 0.947429656982422 "0"
8 0.0165405273437500 "100"
7 0.00766372680664063 "101"
9 0.00628662109375000 "1100"
15 0.00466156005859375 "11010"
6 0.00458145141601563 "11011"
5 0.00319671630859375 "11100"
10 0.00265502929687500 "11101"
4 0.00210571289062500 "111100"
11 0.00152206420898438 "111101"
3 0.00105667114257813 "1111100"
12 0.00102996826171875 "1111101"
13 0.000568389892578125 "1111110"
2 0.000389099121093750 "11111110"
14 0.000308990478515625 "111111110"
0 3.81469726562500e-06 "111111111"
댓글 수: 0
답변 (1개)
charan
2025년 2월 12일
Hi,
If you replace the pixel values with the code and store them in order you get a binary representation of image that is shorter than the original image representation, in this way image compression can be achieved. You can refer to the below code that shows similar workflow on a matrix:
img = randi(15,4)
symbols = unique(img);
counts = histc(img, symbols);
p = counts / sum(counts);
dict = huffmandict(symbols, p)
img_enc = huffmanenco(img(:), dict)'
img2=reshape(huffmandeco(img_enc,dict),4,4)
The "img_enc" shows the encoded image representation. With the dictionary available the image can be decoded from the binary representation.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Denoising and Compression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!