A. JPEG compression process

Source: Internet
Author: User
A. JPEG compression process

JPEG compression is implemented in four steps:
1. Color mode conversion and sampling;
2.DCT transform;
3. Quantification;
4. Code.
Two.
1. Color mode conversion and sampling RGB color system is our most common way of representing color. JPEG uses the YCbCr color system. To use the JPEG basic compression method to process Full-color images, you must first convert the RGB color pattern image data to YCbCr color mode data. Y represents brightness, CB and CR represent Chroma, saturation. Data conversion can be accomplished through the following calculation formulas. y=0.2990r+0.5870g+0.1140b
cb=-0.1687r-0.3313g+0.5000b+128
cr=0.5000r-0.4187g-0.0813b+128
The human eye on the low-frequency data than the high-frequency data has a higher degree of sensitivity, in fact, the human eye on the brightness of the change is more sensitive than the color changes, that is, the Y component of the data is more important. Since the CB component and CR component Data Compare relatively unimportant, you can only take part of the data to deal with. To increase the compression ratio. JPEG usually has two sampling methods: YUV411 and YUV422, which represent the data sampling ratio of Y, CB and CR three components.
The full name of the 2.DCT transform DCT transform is the discrete cosine transform (discrete cosine Transform), which is to convert a group of light intensity data into frequency data in order to know the intensity change situation. If the high frequency of the data to do some modification, and then back to the original form of data, obviously somewhat different from the original data, but the human eye is not easy to identify. In compression, the original image data is divided into 8*8 data element matrices, such as the first matrix of luminance values as follows:
JPEG will be the whole brightness matrix and chroma cb matrix, saturation CR matrix, as a basic unit called MCU. The number of matrices contained in each MCU shall not exceed 10. For example, the ratio of row and column sampling is 4:2:2, then each MCU will contain four brightness matrices, a chroma matrix and a saturation matrix.
When the image data is divided into a 8*8 matrix, each value must be subtracted by 128, then a generation into the DCT transform formula, can achieve the purpose of DCT transformation. The image data value must be subtracted by 128 because the DCT conversion formula accepts a range of digits between 128 and +127.
DCT Transform formula:
X,y represents the coordinate position of a numerical value in the image Data Matrix F (x,y) represents a number of numerical values within the image data matrix u,v representing a value in the matrix after the DCT transformation. F (u,v) represents a value in the matrix after the DCT transformation
U=0 and V=0 C (u) C (v) =1/1.414 u>0 or V>0 C (u) C (v) =1
After the DCT transformation of the Matrix data natural number is the frequency coefficient, these coefficients to f (0,0) The value of the largest, called DC, the remaining 63 of the frequency coefficients are some close to 0 of the positive and negative floating-point number, known as AC.
3. After the quantization image data is converted to the frequency coefficient, a quantization program must be accepted to enter the coding stage. The quantization phase needs two 8*8 matrix data, one is to deal with the brightness of the frequency coefficient, the other is for the chroma of the frequency coefficient, the frequency coefficient divided by the value of the quantization matrix, get the nearest integer with the quotient, that is, complete quantification. When the frequency coefficients are quantified, the frequency coefficients are converted from floating-point numbers to integers, which facilitates the execution of the final encoding. However, after the quantization phase, all data retains only an integer approximation, and some data content is lost again, JPEG provides the following quantization table:
4, Encoding Huffman encoding patent-free problem, become the most commonly used JPEG encoding, Huffman coding is usually done with a complete MCU. When encoding, the DC value of each matrix data and 63 AC value, will use different Huffman coding table respectively, and brightness and chroma also need different Huffman coding table, so need four coding tables altogether, can complete the JPEG coding work smoothly. DC coded DC is the difference coding method of color using difference pulse coding modulation, which is to encode the difference between each DC value and the previous DC value in the same image component. The main reason for DC using difference pulse coding is that in continuous-tone images, the difference is much smaller than the original value, and the number of digits required to encode the difference is much less than the number of digits needed to encode the original value. For example, the difference is 5, its binary represents a value of 101, if the difference is-5, then the positive integer 5, and then convert the binary to 1 of the complement. The so-called 1 complement, is to each bit if the value is 0, then change to 1;bit to 1, then become 0. The difference value 5 should retain the number of digits is 3, the following table is the number of travel value should be retained by the bit and the difference between the content of the comparison.
Add some difference to the front end of the Huffman code value, such as the brightness difference is 5 (101) of the number of digits is 3, then the Huffman code value should be 100, the two connected together is 100101. The following two tables are coded tables for brightness and chroma DC difference. According to the contents of these two forms, the DC difference can be combined with the Huffman code value to complete the coding work of DC.
AC coded AC encoding is slightly different from DC, and before AC coding, 63 AC values must first be sorted by Zig-zag, which is concatenated in the order indicated by the following figure arrows.
63 AC values are arranged, the AC coefficients are converted to intermediate symbols, and the intermediate notation is expressed as rrrr/ssss,rrrr is the number of AC with a value of 0, before the first nonzero AC, SSSS is the number of digits required for the AC value, The relationship between the range of AC coefficients and ssss is similar to that of DC difference bits and difference content tables. If the number of AC numbers with a continuous 0 is greater than 15, then 15/0 is used to denote a continuous 16 0,15/0 called ZRL (Zero Rum Length), and (0/0) is called EOB (Enel of block) to indicate that the remaining AC coefficients are equal to 0, The appropriate Huffman code value is obtained from the corresponding AC coding table, and then the AC value is connected with the intermediate sign value as the index value. For example, a group of brightness in the middle of the 5/3,AC value of 4, first with 5/3 as the index, from the Brightness AC Huffman encoding table found 1111111110011110 Huffman code value, so add the original 100 (4) is to take [5,4] Huffman encoding 1111111110011110100,[5,4] indicates that the AC value of 4 is preceded by 5 zeros. Because of the brightness AC, chroma AC Hoffman Coding table is relatively long, in this omitted to go, interested people can refer to related books.
Achieve the above four steps, namely completes one image the JPEG compression.
Reference [1] Lin Fozong "image File Format (top)--windows programming", Tsinghua University Press,
1996 [2] Li Zhenhui, Li Ren, "Exploring the mysteries of image Files", Tsinghua University Press,
1996 [3] Li Hongsong, Cheng Shi translation "JPEG static data compression standard", study Court Press, 1996

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.