Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jpeg encoding technique

I heard that Jpeg uses Hufman code. What is Huffman code?

like image 619
lital maatuk Avatar asked Feb 08 '11 09:02

lital maatuk


2 Answers

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

like image 54
david99world Avatar answered Oct 13 '22 19:10

david99world


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:

enter image description here

you will have a matrix with DCT coefficients, showing frequency information, concentrating most information in the left superior corner:

enter image description here

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.

enter image description here

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.

enter image description here

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.

like image 24
Jav_Rock Avatar answered Oct 13 '22 19:10

Jav_Rock