I heard that Jpeg uses Hufman code. What is Huffman code?
Huffman coding is a method that takes symbols (e.g. bytes, DCT coefficients, etc.) and encodes them with variable length codes that are assigned according to statistical probabilities. A frequently-used symbol will be encoded with a code that takes up only a couple bits, while symbols that are rarely used are represented by symbols that take more bits to encode.
A JPEG file contains up to 4 huffman tables that define the mapping between these variable-length codes (which take between 1 and 16 bits) and the code values (which is an 8-bit byte). Creating these tables generally involves counting how frequently each symbol (DCT code word) appears in an image, and allocating the bit strings accordingly. But, most JPEG encoders simply use the huffman tables presented in the JPEG standard. Some encoders allow one to optimize these tables, which means that an optimal binary tree is created which allows a more efficient huffman table to be generated.
Have a look at http://www.cs.duke.edu/csed/poop/huff/info/ for a much deeper explanation
Just to complete the answer given by david99world:
Huffman coding is just a final step in jpeg compression. The important compression comes from the Quantization matrix applied to the DCT. What is this? Well, the DCT transformation is just a way to show image information by frequencies. Instead of having a matrix with pixel values like this:
you will have a matrix with DCT coefficients, showing frequency information, concentrating most information in the left superior corner:
Now that you have the DCT coefficients here it comes the real compression step, which is dividing all the values by a Quantization Matrix based on human eye vision. This Matrix will make zero those coefficients containing information not relevant for human eye and will let almost the same the important ones.
Why is this step important for compression? Because now that you have a lot of zeros, Huffman coding will group large amounts of zeros in small code-words, so you are saving storage memory.
You can try to program in Matlab the whole algorithm and you will understand it better. Note that if you apply the Q matrix several times, you will have more compression (more zeros), but also a lower quality image.
I hope this make things clearer for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With