The image compression algorithms can be divided into two main groups. An algorithm in which the original image data will remain unchanged after compression and decompression phases is called a lossless algorithm. LZW and RLE are the most famous types of lossless algorithms. These algorithms are mainly used on image formats that contain a color palette like .gif, .png
and so on
The main limitation in these formats is the number of colors. The colors in each channel cannot exceed 256. So these formats are not suitable for saving true-color images. Also for saving images with non-uniform adjacent pixels these formats are not optimal.
In contrast for saving images with solid background or minimum number of colors they considerably optimize the image size and displaying speed.
In the following figure you can compare several versions of two images, which are saved in the .gif, .png
, and .jpg
formats.
In a lossy compression algorithm, due to the quality that we have specified for compression, some of the image data will be omitted. This will produce more compression and the resulting image will have a smaller size than with the lossless methods. You may imagine that eliminating some image data will reduce the quality and generate a poor noisy image. In fact although we lose some data from the original image, due to the internal algorithm of lossy compressions the changed or lost pixel color will not be noticeable.
In the following image you can see and compare two levels of quality for creating .jpg
images from a raw .bmp
file. As you can see the changed pixels can be recognized if we focus on them.