Image compression seeks to reduce digital image file sizes while maintaining image quality. This is achieved by applying the methods of data compression to the files. An image's file size can be reduced with or without a loss in quality of the image; these are called lossy compression and lossless compression, respectively. Image compression is useful when a computer user wishes to minimize required storage space or maximize data transfer rates of an image.
The first type of image compression is lossy compression. A user seeking to dramatically reduce an image file size may opt for a lossy compression method if some reduction in image quality is worth a significant reduction in file size. Pictures and videos from digital cameras are examples of digital files that are commonly compressed using lossy methods. A user will not be able to restore the original image because there will be compression artifacts, or irreversible alterations, in the image.
A simple method of lossy image compression is to reduce the color space to a smaller set of colors. Color spaces can range from only eight distinct colors to millions of colors. The larger the color space, the more data is required to specify a particular color. Converting an image to grayscale, or to shades of gray, is a similar lossy image compression technique.
Lossless image compression is any method of reducing an image's file size without sacrificing information about the image — an identical image to the original can always be retrieved. Lossless forms of data compression are necessary when reductions in quality are deemed unacceptable. Medical imaging, technical drawings, and astronomical observations typically use lossless compression techniques.
One lossless image compression method is called run-length encoding. Often, simple images have many repetitive pixels, or small points of color. For example, in an image with a black background, the entire top row of pixels may be black. The run-length encoding method stores this string of black pixels in two values: one for the color and one for the number of pixels in the string. This method can store the same amount of information with much less data.
A Joint Photographic Experts Group (JPEG) is an example of an image compression method with a variable level of compression. JPEG compression typically leaves behind some amount of compression artifacts, but it can reduce file sizes by more than 10 times with only minor losses in quality. Some JPEGs will load an image with progressively greater detail, allowing the user to see a preview of the image as it loads. These aspects of the JPEG image format have made it very popular on the World Wide Web.