Picture compression is how important, perhaps many people may not have an intuitive understanding, for example, a 800x800 size of ordinary pictures, if not compressed, probably around 1.7MB, this volume if the text file is enough to save a 920,000 words of the great masterpiece "Red Mansions", Today, most of the images on the Internet use JPEG compression technology, that is, the JPG file used by everyone, usually JPEG files relative to the original image, can get 1/8 compression ratio, so high compression rate is how to do it?
JPEG is able to obtain such a high compression ratio because of the use of lossy compression technology, so-called lossy compression, is to remove the unimportant parts of the original data, so that can be saved with a smaller volume, this principle is actually very common, For example, 485194.200000000001 this number, if we save with 485194.2来, is a "lossy" method of preservation, because the "0.000000000001" after the decimal point belongs to the unimportant part, so it can be ignored. JPEG the entire compression process is basically followed by this step:
1. Dividing the data into "important parts" and "unimportant parts"
2. Filter out unimportant parts
3. Save
Step One: Image segmentation
The first step of the JPEG algorithm is to split the image into small, 8x8-sized chunks that are handled individually throughout the compression process. In the following we will take a very classic picture, this image is called Lenna, is said to be the world's first JPG pictures, this picture since the birth of the day, and the image processing knot Yuanyuan, accompanied by countless science and technology otaku spent a sleepless night, is meritorious, interested friends can in here 's a story about this picture.
Step Two: Color space conversion rgb->ycbCR
so-called " Color Space ", refers to the expression of color mathematical model, such as our common" RGB "model, is the color decomposition into three components of red and green blue, so that a picture can be decomposed into three gray-scale, mathematical expression, each 8x8 pattern, can be expressed as three 8x8 matrix, where the range of values generally in [ 0,255].
Different color models have different applications, such as RGB models suitable for self-illumination patterns such as displays, while in the printing industry, the use of ink printing, the color of the pattern is generated by reflection of light, usually using the CMYK model, and in the JPEG compression algorithm, You need to convert the pattern into a ycbcr model, where Y is the luminance (luminance), and CB and CR represent the "chromatic aberration" of green and red respectively.
The concept of "chromatic aberration" originated in the television industry, the earliest TV is black and white, then the transmission of TV signal only need to transmit the brightness signal, that is, the y signal can be, after the appearance of the color TV, people in the Y signal to add two color difference signal to transmit colour information, the purpose is to be compatible with the black and white machine, Because the black and white only needs to process the y signal in the signal.
According to the three-color principle, people found that the three colors of red, green and blue contribute to the brightness is different, the green "brightness" the largest, the most dark blue, set the red contribution of the brightness of the share of KR, the share of the blue contribution of the KB, then the brightness of
based on experience, kr=0.299,kb=0.114, then
The color difference between blue and red is defined as follows
The mathematical formula for converting RGB to YCBCR can eventually be
The YCBCR model is widely used in the compression of images and videos, for example, if you can look at the interface behind the TV or DVD, you can find the chromatic aberration interface.
It makes sense to remember do we have to mention the basic principle of lossy compression at the beginning of the article? The first thing to do in lossy compression is to "separate the important information from the unimportant information", which is exactly what YCbCr can do. For the human eye, the change of light and shade in the image is more easily perceived, which is caused by the construction of the human eye. There are two photosensitive cells on the retina, the rods that perceive the change in brightness, and the cones that perceive the color, and because the rods are much larger than the cones, we are more likely to perceive light and shade details. For example, the picture below
As you can see, the details of the luminance map are richer. After the JPEG converts the image to YCbCr, it is possible to do different processing for the important degree of the data. This is the reason why JPEG uses this color space.
JPEG algorithm decryption