JPG Compress 2



Jpg

Alex Townsend, March 2017

Optimizilla is the ultimate image optimizer to compress your images in JPEG and PNG formats to the minimum possible size. This online image optimizer uses a smart combination of the best optimization and lossy compression algorithms to shrink JPEG and PNG images to the minimum possible size while keeping the required level of quality. This online image optimizer uses a smart combination of the best optimization and lossy compression algorithms to shrink JPEG and PNG images to the minimum possible size while keeping the required level of quality. Upload up to 20 images. Wait for the compression to.

Compress

Contents

What is JPEG?

JPEG stands for Joint Photographic Experts Group, which was a group of image processing experts that devised a standard for compressing images (ISO).

So, JPEG (or JPG) is not really a file format but rather an image compression standard. The JPEG standard is complicated with many different options and color space regulations. It was not widely adopted. A much simpler standard version was advocated at the same time, called JFIF. This is the image compression algorithm that most people mean when they say JPEG compression, and the one that we will be describing in this class. Note that the file extensions .jpeg and .jpg have stuck, even though the underneath algorithm is (strictly speaking) JFIF compression.

The underlying assumptions of the JPEG algorithm

The JPEG algorithm is designed specifically for the human eye. It exploits the following biological properties of human sight:

(1) We are more sensitive to the illuminocity of color, rather than the chromatric value of an image, and

(2) We are not particularly sensitive to high-frequency content in images.

Jpg Compress 200

The algorithm can be neatly broken up into several stages: There is an input image I, which goes through the following process:

1) A colour transform, 2) A 2D discrete cosine transform on 8x8 blocks, 3) A quantization (filtering) stage, 4) Huffman encoding.

Finally, a compressed image is returned in the .jpg file format. This format contains the compressed image as well as information that is needed to uncompressed, with other information to allow for reexpanding the image.

An uncompressed image of mixed peppers

MATLAB has various images uploaded into MATLAB. Here, is one of some peppers:

It currently requires about the following number of bits to store:

Color transform: Convert RGB to YCbCr

Right now, the image is stored in RGB format. While this colorspace is convenient for projecting the image on the computer screen, it does not isolate the illuminance and color of an image. The intensity of color is intermixed in the colorspace. The YCbCr is a more convenitent colorspace for image compression because it separates the illuminance and the chromatic strength of an image.

Plot Y'CbCr colorspace

Let's see what that colorspace looks like.

Our eyes are senstitive to illuminance, but not color

Since our eyes are not particularly sensitive to chrominance, we can 'downsample' that stuff. Here, we remove x100 amount of 'color' from the image and see that it has barely changed:

Eyes are senstitive to intensity

However, if we downsample the illuminance by x10, then there is a noticeable difference. (You'll have to zoom in to see it.)

JPEG downsampling

Here, we will be a little conservative and downsample the chrominance by only a factor of 2.

The 2D discrete cosine transform

Once the image is in YCrCb color space and downsampled, it is partitioned into 8x8 blocks. Each block is transformed by the two-dimensional discrete cosine transform (DCT). Let's extract one 8x8 block of pixels for demonstration, shown here in white:

We apply the DCT to that box:

Quantization table

Next we apply a quantization table to Y, which filters out the high frequency DCT coefficients:

The number of nonzero DCT coefficients after quantization is:

We now apply this compression to every 8x8 block. We obtain:

Compression so far

The quantization step has successfully compressed the image by about a factor of 7.

Jpg Compress 250 Kb

The formula above is obtained by noting that we downsampled in Cr and Cb are downsampled.

Huffman encoding

We now encode the DCT blocks using Huffman encoding:

Jpeg Compressor 200kb

Final compression

Jpeg Compressor 2019

Jpg compress 2mb

We have successfully reduced the pepper image by about x7, while being extremely conservative:

A different image

How To Reduce The Size Of A Picture To 2mb

The images of peppers is not ideal for JPEG. Here is an image for which JPEG gets a better compression rate (of about x30).

Here's what the images look like:


Published with MATLABĀ® R2016a