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.
Best Answer