Traditional Culture Encyclopedia - Photography major - Is there any difference between compressing jpg at 85% and 100%?
Is there any difference between compressing jpg at 85% and 100%?
You can take a look at the compression principle below
Your Nokia achieves compression during quantization and encoding. The first two steps are unchanged on your mobile phone. The only thing is that when saving, it will be smaller and there will be missing pixels. The 80% compression rate is not easy to see with the human eye. But if you want to print, you still need to do it without compression for a certain process, such as if you are developing a 20-inch large-size photo.
The following is the principle of JPG compression
JPEG compression is implemented in four steps:
1. Color mode conversion and sampling;
2 .DCT transform;
3. Quantization;
4. Encoding.
2.
1. Color mode conversion and sampling The RGB color system is our most commonly used way of expressing color. JPEG uses the YCbCr color system. If you want to use the JPEG basic compression method to process full-color images, you must first convert the RGB color mode image data into YCbCr color mode data. Y represents brightness, Cb and Cr represent hue and saturation. Data conversion can be completed through the following calculation formula. 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 has a higher sensitivity to low-frequency data than to high-frequency data. Sensitivity, in fact, human eyes are much more sensitive to changes in brightness than changes in color, which means that the data of the Y component is more important. Since the data of Cb and Cr components are relatively unimportant, only part of the data can be processed. to increase the compression ratio. JPEG usually has two sampling methods: YUV411 and YUV422, which represent the data sampling ratio of the three components Y, Cb and Cr.
2. DCT Transform The full name of DCT transform is Discrete Cosine Transform, which refers to converting a set of light intensity data into frequency data in order to know the intensity changes. If the high-frequency data is modified and then converted back to the original form, it will obviously be somewhat different from the original data, but it is not easy for human eyes to recognize it. When compressing, the original image data is divided into an 8*8 data unit matrix. For example, the content of the first matrix of brightness values ??is as follows:
JPEG combines the entire brightness matrix with the chroma Cb matrix, saturation Cr matrix, and visual It is a basic unit called MCU. The number of matrices contained in each MCU shall not exceed 10. For example, if the ratio of row and column sampling is 4:2:2, each MCU will contain four brightness matrices, a chroma matrix and a saturation matrix. After the image data is divided into an 8*8 matrix, each value must be subtracted by 128, and then inserted into the DCT transformation formula one by one to achieve the purpose of DCT transformation. The image data value must be subtracted by 128 because the DCT conversion formula accepts numbers in the range -128 to +127. DCT transformation formula:
x, y represents the coordinate position of a certain value in the image data matrix f(x, y) represents several values ????in the image data matrix u, v represents a certain value in the matrix after DCT transformation The coordinate position F(u,v) of a value represents a certain value in the matrix after DCT transformation u=0 and v=0 c(u)c(v)=1/1.414 u>0 or v>0 c(u )c(v)=1 The natural numbers of the matrix data after DCT transformation are frequency coefficients. These coefficients have the largest value of F (0, 0), which is called DC. The remaining 63 frequency coefficients are mostly close to 0. Positive and negative floating point numbers are collectively called AC.
3. Quantization After the image data is converted into frequency coefficients, it must undergo a quantization procedure before entering the encoding stage. The quantization stage requires two 8*8 matrix data. One is the frequency coefficient specifically dealing with brightness, and the other is the frequency coefficient for chroma. Divide the frequency coefficient by the value of the quantization matrix to obtain the nearest integer to the quotient, that is Complete quantification. After the frequency coefficient is quantized, the frequency coefficient is converted from a floating point number to an integer, which facilitates the final encoding. However, after the quantization stage, all data only retains integer approximations, and some data content is lost again. The quantization table provided by JPEG is as follows:
4. Encoding Huffman encoding has no patent rights and has become the most popular method of JPEG. The commonly used encoding method, Huffman encoding is usually performed with a complete MCU. When encoding, the DC value and 63 AC values ??of each matrix data will use different Huffman coding tables respectively, and brightness and chroma also require different Huffman coding tables, so four coding tables are needed in one go. Complete JPEG encoding work smoothly. DC encoding DC is a difference encoding method that uses difference pulse coding modulation, that is, the difference between each DC value and the previous DC value in the same image component is obtained for encoding.
The main reason why DC uses difference pulse coding is that in continuous-tone images, the difference values ??are mostly smaller than the original values. The number of bits required to encode the difference values ??will be smaller than the number of bits required to encode the original values. Much less. For example, if the difference is 5, its binary representation is 101. If the difference is -5, first change it to a positive integer 5, and then convert its binary representation into the complement of 1. The so-called complement of 1 means that if the value of each Bit is 0, it is changed to 1; if the Bit is 1, it is changed to 0. The number of bits that should be retained for the difference value 5 is 3. The following table lists the comparison between the number of bits that should be retained for the difference value and the content of the difference value.
Add some difference Huffman code values ??to the front end of the difference. For example, if the brightness difference is 5 (101) and the number of digits is 3, then the Huffman code value should be 100. Both When connected together they are 100101. The following two tables are coding tables for brightness and chroma DC differences respectively. According to the contents of these two tables, the Huffman code value can be added to the DC difference value to complete the DC encoding work.
AC encoding The AC encoding method is slightly different from DC. Before AC encoding, the 63 AC values ??must first be sorted by Zig-zag, that is, concatenated in the order indicated by the arrows in the figure below.
After 63 AC values ??are arranged, convert the AC coefficients into intermediate symbols. The intermediate symbols are represented as RRRR/SSSS. RRRR refers to the number of ACs with a value of 0 before the non-zero AC. SSSS refers to the number of bits required for the AC value. The corresponding relationship between the range of the AC coefficient and the SSSS is similar to the comparison table between the number of DC difference bits and the difference content. If the number of consecutive 0 ACs is greater than 15, 15/0 is used to represent 16 consecutive 0s, 15/0 is called ZRL (Zero Rum Length), and (0/0) is called EOB (Enel of Block) It is used to indicate that the remaining AC coefficients are all equal to 0. Use the intermediate symbol value as the index value, find the appropriate Huffman code value from the corresponding AC coding table, and then connect it to the AC value. For example, the intermediate symbol of a certain group of brightness is 5/3 and the AC value is 4. First, use 5/3 as the index value and find the 1111111110011110 Huffman code value from the Huffman coding table of brightness AC, so add the original 100 (4 ) is the Huffman code 1111111110011110100 used to take [5, 4]. [5, 4] means that there are 5 zeros in front of the AC value of 4. Since the brightness AC and chroma AC Huffman coding tables are relatively long, they are omitted here. Those who are interested can refer to relevant books. Implementing the above four steps will complete the JPEG compression of an image.
References [1] Lin Fuzong, "Image File Format (Part 1) - Windows Programming", Tsinghua University Press, 1996 [2] Li Zhenhui and Li Ren, editors, "Exploring the Mysteries of Image Files", Tsinghua University Press, 1996[3] "JPEG Still Data Compression Standard" translated by Li Hongsong and Cheng Shi, Xueyuan Press, 1996
- Previous article:In 2009, Pan Yueming was killed in a car accident. What about the actress in his car?
- Next article:How to make popular posters
- Related articles
- Why is Taian called the ghost capital?
- What are the ten most beautiful villages in China?
- What lens of humanistic photography?
- What is line art?
- What does the focal length parameter of SLR camera lens mean?
- Four essays on personal feelings after becoming famous.
- Ten scenic spots that Enshi must visit What are the top ten scenic spots that Enshi must visit?
- France deployed100000 military police. What kind of existence is the French gendarmerie?
- Principle of laser sky lens
- Dreaming of the omen of the dead man's studio