Image compression applies data compression to pictures, usually represented by raster images. Nearby pixels often have related shades; an encoder can exploit that structure. A flat region invites run-length encoding, while lossy block averaging trades fine detail for fewer stored samples. The choice depends on whether exact pixel values matter and on the patterns in the image.
Lossless source coding recovers the encoded pixel values exactly, including sharp text or numerical image data. Lossy compression preserves an approximation and can remove features that later image processing might need. A visually smooth result is therefore a different promise from exact recovery. Neither method has a universal compression ratio: the chosen file format, its file header and the particular image all matter.
PNG is a real format with lossless source coding of its encoded image data. Its specified compression uses Deflate on reversibly filtered rows, rather than our toy RLE format. The lossy block averaging example is also a teaching format, not a description of PNG. A lossy preprocessing step followed by saving as PNG preserves the already changed pixels, not the earlier original.[ref]

Articles by others on the same topic (NaN)

Image compression is the process of reducing the file size of an image by removing redundant or unnecessary data while preserving its visual quality as much as possible. This is particularly important for saving storage space, speeding up the transfer of images over the internet, and optimizing images for various devices and applications. There are two main types of image compression: 1. **Lossy Compression**: This method reduces file size by permanently eliminating certain information, especially in a way that is not easily perceivable to the human eye.