MATLAB: How to change the Encoded array of Image created using Huffman Code into the compressed Image

digital image processingimage processing

Actually I have used Both Build in function of huffmanenco and self build the entire code, it is converting the input image to the variable length binary array of numbers as one get using huffman tree, but then how to convert the encoded array into compressed Image, to utilize compression real life.

Best Answer

The result of huffmanenco is a vector of values that are all 0 or 1 (double precision).
You can fopen() a file for writing, and fwrite(fid, TheVector, 'ubit1') and then fclose the file. The resulting file will be the compressed image.
However, the bit stream by itself is not enough to recreate the image. In order to recreate the image, you need also
  • information about the size of the image and the order you encoded the pixels
  • the encoding dictionary, listing the bit patterns and their associated symbols
Also, when you fwrite with ubit1, you might not happen to be writing a multiple of 8 bits. In that situation, fwrite sets the remaining bits in the last byte to 0 and writes the complete byte. You need to figure out how you are going to know to not try to decode the extra padding.
Related Question