When you browse the web, you can always see a variety of beautiful pictures. After downloading these pictures, it may be JPG format or JPEG format. Of course, there are other PNG, GIF and other formats, compared to PNG. In other formats, the JPG format is relatively small, which is why the JPG format is popular. I believe many partners don’t know what the relationship between JPG and JPEG is. In order not to let everyone always in the fog, today Theencarta will give you the knowledge of popular science JPG and JPEG.

Difference between jpg and jpeg

The JPG format is relatively small in size because it uses a series of compression algorithms. The drawback of compressing the image is that it sacrifices some of the details of the picture compared to the original image. These missing details or permissions are visible to the naked eye. Out, perhaps difficult to find with the human eye, the compression algorithm for the purpose of reducing the volume by sacrificing the fineness of the picture, we call it “lossy compression” or “destructive compression”, today, IT home Just talk to everyone about the basic principles of JPEG image compression.

Second, the relationship between JPEG and JPG

Many readers may have such doubts. JPEG and JPG look so similar. Are they the same image format? What is the relationship between JPEG and JPG? Before answering this question, we must first understand that JPEG comes.

JPEG, the full name of “Joint Photographic Experts Group”, translated into Chinese, is the “Joint Photographic Experts Group”, an organization founded in 1986. In 1992, the organization released the “JPEG standard”, which is a kind of A standard developed for image compression.

Image files compressed using the JPEG standard are called “JPEG files”. The extensions of such files are usually JPG, JPEG, JPE, JFIF, and JIF. Among these file formats, JPG is the most widely used.

If JPEG refers to the Joint Photographic Experts Group, then JPEG and JPG are the relationship between the organization that developed the compression standard and the format of the image compressed by the compression standard developed by the organization;

If JPEG refers to the JPEG compression standard, then JPEG and JPG are the relationship between a compression standard of an image and a format of a picture compressed by the standard;

If JPEG refers to the suffix of an image file, the relationship between JPEG and JPG is two different formats of the image compressed by the JPEG standard.

Third, color space conversion

To compress a picture, you first need to know what is included in the picture. When decomposing the content of the picture, the first step is to perform color space conversion.

The so-called color space refers to a set of values ​​that describe the color of an image. The more common color spaces are RGB and CMYK.

RGB, that is, three sets of values ​​are used to represent red, green, and blue, respectively, and red, green, and blue colors are displayed in different degrees, and different colors are displayed. Usually the RGB color model is used for the display of the display.

CMYK, which uses four sets of values ​​to represent cyan, magenta, yellow, and black, respectively, and cyan, magenta, yellow, and black, in different proportions, will show different colors. Usually CMYK’s color model is used for printing.

In the process of JPEG compression of images, how do you use numerical values ​​to represent image content? In fact, JPEG quantizes the color of the image instead of RGB mode, not CMYK mode, but YCbCr mode, where Y is the brightness, Cb is the chroma (blue), and Cr is the chroma (red) ). So the question is, why does JPEG not use RGB and CMYK color models when compressing images, but instead adopts the seemingly odd mode of YCbCr? This also needs to start from the working mechanism of the human eye.

The reason why our eyes can perceive images is because the human eye contains cones and rods. Among them, cones have the ability to perceive color, while rods have the ability to sense brightness, usually in our eyes. The number of rod cells is relatively large, so the human eye is more sensitive to brightness than to color. Just as you turn off the lights, you can gradually see the things around you in the dark, and you may not be so sensitive to the color of the things around you.

JPEG takes advantage of this feature of the human eye to separate brightness and color when compressing images.

Since the human eye is sensitive to brightness, JPEG does not change much brightness, and the human eye is not sensitive to color. Scientific research shows that the human eye can distinguish 10 million different colors. Compared to the computer, it is not so accurate), so before the human eye begins to notice that the color is wrong, JPEG compresses the color, so that even if the image loses some details, the human eye is not easy to capture.

The color space conversion performed by JPEG when compressing an image refers to converting RGB to YCbCr.

Fourth, reduce sampling

In the YCbCr model, the amount of information contained in the Cb channel and the Cr channel is far less than the amount of information contained in the Y channel. At the same time, the sensitivity of the human eye to color is limited. Therefore, the compression algorithm of JPEG is mainly for Cb and Cr. The data in the channel is downsampled, and the sampling ratio can be 4:4:4 (no downsampling), 4:2:2 (sampling in multiples in horizontal 2), and 4:2:0 (in horizontal direction and Sampling in multiples of 2 in the vertical direction), where 4:2:0 is most common.

Five, discrete cosine transform (DCT)

Usually we think that in a square of 8*8 pixels, the pixels inside it are often very similar, so when this step is taken, JPEG divides the image into 8*8 pixel blocks one after another.

Each pixel block is coded using a discrete cosine transform. French mathematician Fourier tells us that almost all periodic functions can be represented by a series of “string waves”, that is, by a weighted one. By adding the different cosine values ​​of the series, we can reconstruct our original image. Finally, each 8*8 pixel block will generate a new 8*8 digital matrix through a specific function.

The above is a small series to explain the relevant knowledge of the popular JPG and JPEG image formats. I believe everyone has a deeper understanding of the JPG image format. JPG is a lossy compressed image format, which is relatively small in size and fast in opening speed. However, the picture is relatively unclear, and you can choose the image format according to your needs.