compression - How to store and subsequently decode Huffman table -


this question has answer here:

i have huffman table pixel intensities in image. need store in binary file in dht format jpeg images. receiver can extract these values @ loss how reconstruct table. describe in great detail how generated , stored table in case sorting sequence affects end result.

generate table

  • in list make pairs of (frequency, intensity) each intensity [0,255] , remove pairs 0 frequency.

  • sort list in ascending order of frequency. multiple pairs have same frequency, sorted intensity, e.g. [ (1, 7), (1, 55), (1, 107), (2, 4), (2, 19), etc ]

  • pop 2 firstmost pairs, first being left child , second right child, put them in parent node , sort list again. when sorting list, same frequency first put individual pairs , parent nodes in ascending length order, e.g. [ (1, 107), (2, 4), (2, 19), (2, ((1, 7), (1, 55))) etc ]

  • iterate build whole tree , walk though codes.

store table

to store table, header formed sequentially following:

  • the number of levels in tree (tends 16 anyway)

  • for each level (1-16) how many codes there are, e.g. 0 (for 1), 2 (for 2), 1 (for 3), etc

  • then write intensities in order, e.g. 2 level 2, 1 level 3, etc.

  • in order make sure there have been no mix ups, codes each level had been sorted numerically, e.g. level 6: 000100, 000101, 001000, 001001, 001011

codes after extraction

so can extract these , values in table below. i've read 1 needs reconstruct codes don't understand process. example, level 2 codes supposed 10 , 11. how know it's not 00 , 01 instead? have provided first few levels , appreciate if explain process me going.

bits | number -----+-------- 1    |    0 2    |    2 3    |    1 4    |    1 5    |    2 6    |    5 7    |    6 8    |    6 9    |   17 etc 

all need send number of bits in code each symbol. 0 can indicate symbol not present , not coded. number of bits can huffman coded , run-length encoded, done in deflate format.

given set of code lengths, need make sure bit sequences assigned same way on both ends. done using canonical huffman code, codes assigned in symbol order within each bit length.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -