Like any other application of data compression , image compression is based on either converting the original data into a completely reconstructable form that requires less storage space or on removing data whose loss is barely noticeable. There are many formats for image files ( graphic formats ), but many of them are out of date and many do not support compression, since they are formats for exchange among graphics programs.
In the lossless compression no information is lost. The data is presented differently than before, in that certain redundancies are recognized and removed. For example, repeating bit sequences can be stored once in a dictionary and then only represented by their number. Well-known methods are run length coding , LZW or Huffman coding . Any general compression technique that can be applied to other types of data, such as text, can be used.
Lossless image types include:
- Portable Network Graphics (PNG) compresses images to keep them small in size by finding patterns in a photo and compressing them together. The compression is reversible. Once a PNG file is opened, the image is exactly restored. The PNG graphic format uses Deflate , a combination of LZ77 and Huffman coding , as the compression method . The good compression of PNG is explained by the additional use of predictive coding (also called “pre-filter” for PNG). The next color values are predicted from empirical values and only the deviations of the prediction from the actual image information are stored.
- The graphic format GIF , on the other hand, only uses the Lempel-Ziv-Welch algorithm for compression and therefore usually does not achieve as good compression as PNG. In addition, it can only display a maximum of 256 colors per single image, but also animations . With GIF, the color information is stored in a color table . This can contain up to 256 different entries that can be freely selected from 256 3 ≈ 16.7 million possible color values. For simple drawings , black and white photographs , 256 colors or shades of gray are usually still sufficient today. More complex images such as color photos or drawings with extensive color gradients must therefore be reduced to 256 colors or less before being saved ( color quantization ). The resulting color levels or dithering effects are particularly annoying with large images.
- Windows Bitmap (BMP) is a format that is only available to Microsoft . It's lossless, but it's not used often. Windows bitmaps allow color depths of 1, 4, 8, 16, 24 or 32 bpp (bits per pixel ), although not all bits actually have to be used with 16 and 32 bpp .
- RAW - Many digital SLR cameras contain and store all light data received from the camera sensor . These file types are usually quite large. In addition, there are different versions of RAW and certain software may be required to manipulate the image files.
A good compression factor can only be achieved with these methods if the images are favorable for these compression algorithms . This means that they should have the largest possible areas with the same color or exactly the same pattern, with PNG possibly also with color gradients.
Converting an image back from a lossy graphics format to a lossless graphics format cannot restore the original image data.
In lossy compression , an attempt is made to keep the loss of information imperceptible or at least aesthetically tolerable. These methods take advantage of the fact that small changes in color are not visible to the eye. Similar to lossy audio compression, image compression is based on a model of human perception. The compression algorithm should preferably remove the image information that goes beyond the receptivity of human image perception. In contrast to audio compression, however, the perception model is not explicitly formulated and incorporated into the algorithms, but more intuitive.
JPEG and JPEG 2000
In the JPEG process, the image is transformed using a system of basic functions . With JPEG this is the discrete cosine transformation , with JPEG 2000 the wavelet transformation . In this way one obtains another, equivalent representation of the image, which consists of the coefficients for these basic functions. With JPEG these are the amplitudes of the so-called spatial frequencies , with JPEG 2000 a kind of mean values over 4, 16, 64, ... pixels. These coefficients are changed by the quantization . Small coefficients disappear completely and the larger ones are set to the next best value. So they can be represented with fewer bits. Finally, lossless data compression is carried out.
The newer JPEG 2000 has not yet been able to establish itself, however, as the algorithms required for digital cameras and other portable devices are too computationally expensive and there are legal uncertainties regarding licensing ( software patents ).
The greatest visual problems ( compression artifacts ) with excessive JPEG compression are caused by the formation of so-called block artifacts , which arise when the image is divided into small blocks, as well as ringing , a consequence of the unfavorable behavior of the discrete cosine transformation with hard color transitions.
Fractal image compression
Another lossy method that has not been able to gain broad acceptance in graphic formats is fractal image compression. It is based on the knowledge of chaos theory that almost every picture shows self-similarity . In this case, groups of the next smaller order of magnitude (4 × 4 points) similar to groups of pixels of a certain size (e.g. 8 × 8 points) are searched for in the same image. Instead of the actual groups, only the position of the similar reference groups which have less image data are then stored. This procedure essentially corresponds to a codebook procedure, with the difference that the codebook does not have to be saved separately, but is available in the same image. Since the search for similar groups can be quite time-consuming, neural networks are used here. However, the decoding is no more complex than with conventional methods.
Compression method in comparison
The common formats have advantages and disadvantages and are therefore more or less suitable for the respective purpose. Computer graphics that contain hard edges - such as simple graphics or screenshots - can usually be compressed better using lossless methods, as the following comparison shows:
PNG: 1007 bytes
For photographs and similar non-graphic images, JPEG is the first choice among the popular formats if storage space is an issue. Lossless formats like PNG are usually not suitable for photographs as they produce significantly larger files. In the case of GIF, there is also the limitation of 256 colors per single image.
In the professional sector (e.g. in prepress ) loss-free formats or vector graphics are mostly used, since there the possibility of multiple processing is more important than the memory consumption; in addition, the image quality is better than JPEG. TIFF is usually used here because it also supports the CMYK color model used in print shops . Lossless raw data formats also offer the greatest possibilities and best quality for photographs. But there are also “mixed formats” such as JPEG 2000, in which lossless and lossy compression can be combined.
- Tilo Strutz: Image data compression . 5th edition. Springer Vieweg, Wiesbaden 2017, ISBN 978-3-8348-1427-2 .
- Compression FAQ - Frequently asked questions about data compression
- Overview article on lossless image compression (PDF file; 1.24 MB)