Monday, March 28, 2016

Write down the Hufman coading algorithm used in loseless compression

 The Hufman coading algorithm used in loseless compression :


1. Read a BMP image using image box control in Delphi language. The TImage control can be used to display a graphical image - Icon (ICO), Bitmap (BMP), Metafile (WMF), GIF, JPEG, etc. This control will read an image and convert them in a text file.

2. Call a function that will Sort or prioritize characters based on frequency count of each characters in file.

3. Call a function that will create an initial heap. Then reheap that tree according to occurrence of each node in the tree, lower the occurrence earlier it is attached in heap. Create a new node where the left child is the lowest in the sorted list and the right is the second lowest in the sorted list.

4. Build Huffman code tree based on prioritized list. Chop-off those two elements in the sorted list as they are now part of one node and add the probabilities. The result is the probability for the new node.

5. Perform insertion sort on the list with the new node.

6. Repeat STEPS 3,4,5 UNTIL you only have 1 node left.

7. Perform a traversal of tree to generate code table. This will determine code for each element of tree in the following way.
The code for each symbol may be obtained by tracing a path to the symbol from the root of the tree. A 1 is assigned for a branch in one direction and a 0 is assigned for a branch in the other direction. For example a symbol which is reached by branching right twice, then left once may be represented by the pattern '110'. The figure below depicts codes for nodes of a sample tree.
*
/ \
(0) (1)
/ \
(10)(11)
/ \
(110) (111)

8. Once a Huffman tree is built, Canonical Huffman codes, which require less information to rebuild, may be generated by the following steps: Step 1. Remember the lengths of the codes resulting from a Huffman tree generated per above. Step 2. Sort the symbols to be encoded by the lengths of their codes (use symbol value to break ties). Step 3. Initialize the current code to all zeros and assign code values to symbols from longest to shortest code as follows:

(A). If the current code length is greater than the length of the code for the current symbol, right shift off the extra bits.

(B). Assign the code to the current symbol.

(C). Increment the code value.

(D). Get the symbol with the next longest code.

(E). Repeat from A until all symbols are assigned codes.

9. Encoding Data- Once a Huffman code has been generated, data may be encoded simply by replacing each symbol with its code.

10. The original image is reconstructed i.e. decompression is done by using Huffman Decoding.

11.Generate a tree equivalent to the encoding tree. If you know the Huffman code for some encoded data, decoding may be accomplished by reading the encoded data one bit at a time. Once the bits read match a code for symbol, write out the symbol and start collecting bits again.

12. Read input character wise and left to the tree until last element is reached in the tree.

13. Output the character encodes in the leaf and returns to the root, and continues the step 12 until all the codes of corresponding symbols is known.
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE

No comments:

Post a Comment