1. Bitmap Imaging
Bitmap (or raster) imaging is a method of storing digital images using a grid of tiny individual elements called pixels. Each pixel holds color information, and together, they form the complete image. The clarity and quality of a bitmap image depend on its resolution (the total number of pixels) and color depth (how many colors each pixel can display).
- Structure of Bitmap Images:
- Bitmap images have a fixed resolution. For example, a 1920×1080 image has 2,073,600 pixels arranged in a grid.
- Each pixel contains color values, typically stored as RGB (Red, Green, and Blue) values.
- RGB (Red, Green, Blue) is used in digital screens instead of RGY (Red, Green, Yellow) because RGB aligns with how the human eye perceives color through trichromatic vision, where our eyes have three types of cone cells sensitive to red, green, and blue wavelengths.
- Uses of Bitmap Images:
- Bitmap images are popular in photography, web graphics, and digital art, as they allow for highly detailed visuals. However, they do not scale well; enlarging them results in pixelation, as each pixel becomes more visible.
Example:
- Photographs and detailed artwork are usually stored in bitmap formats like JPEG, PNG, and BMP because these formats can capture a high level of detail and color accuracy.
2. Image Compression
Bitmap images often create large file sizes because each pixel holds specific color data. Compression reduces the file size, making it easier to store and share images without compromising quality too much. Compression works by reducing or simplifying the color data in an image, often with minimal visible impact.
Types of Compression:
Compression comes in two main types: lossy and lossless.
- Lossy Compression:
- What It Does: Discards some data permanently to reduce file size. It achieves higher compression ratios, which significantly reduces file sizes but may cause a slight reduction in image quality.
- How It Works: In lossy compression, similar colors and pixel patterns are combined and simplified. This is often imperceptible to the human eye, but repeated compression can cause visible degradation.
- Common Formats: JPEG is a popular lossy format. It achieves high compression rates by reducing detail in areas the human eye is less likely to notice.
- Lossless Compression:
- What It Does: Compresses data without losing any information, meaning the original image can be perfectly restored.
- How It Works: Lossless compression works by finding and eliminating repetitive data patterns without removing detail. While the file size reduction is usually smaller than with lossy compression, no quality is lost.
- Common Formats: PNG and GIF are widely used lossless formats. They are ideal for graphics that need to retain exact details, like logos and icons.
Lossless Compression Algorithms
- Huffman Coding:
- Uses variable-length codes based on the frequency of characters in the data. Commonly used in file compression formats.
- Lempel-Ziv-Welch (LZW):
- A dictionary-based algorithm that replaces repeated occurrences of data with shorter codes. Used in GIF and TIFF formats.
- Run-Length Encoding (RLE):
- Compresses sequences of repeated characters or data by storing the value and the count of occurrences. Often used in bitmap images.
- Deflate:
- Combines LZ77 compression and Huffman coding. Used in ZIP files and PNG images.
- Brotli:
- A newer compression algorithm that provides better compression ratios than Deflate. Often used for web content compression (HTTP/2).
- Bzip2:
- Uses the Burrows-Wheeler transform and a combination of Huffman coding and RLE. Commonly used in Unix-like systems for file compression.
- Zstandard (Zstd):
- A fast compression algorithm that provides high compression ratios and speed, often used in modern applications.
- PPM (Prediction by Partial Matching):
- A statistical modeling-based algorithm that predicts the next character based on previous characters. It achieves high compression ratios for text.
Lossy Compression Algorithms
- JPEG (Joint Photographic Experts Group):
- A widely used image compression standard that uses a form of lossy compression based on the discrete cosine transform (DCT).
- MP3 (MPEG Audio Layer III):
- A popular audio compression format that reduces file size by removing audio frequencies that are less audible to humans.
- AAC (Advanced Audio Codec):
- A lossy audio compression format that provides better sound quality than MP3 at similar bit rates, commonly used in streaming and broadcasting.
- MPEG-4:
- A video compression standard that uses lossy techniques to reduce the size of video files while maintaining quality. Includes H.264 and H.265 (HEVC).
- WebP:
- An image format developed by Google that provides lossy compression with better quality and smaller file sizes compared to JPEG.
- OGG Vorbis:
- An open-source audio compression format that provides high-quality sound at smaller file sizes compared to MP3.
- HEIF (High Efficiency Image Format):
- An image format that uses lossy compression (often based on HEVC) to achieve higher quality at smaller sizes compared to JPEG.
- Speex:
- An audio compression format designed for voice, providing variable bit rates and high compression ratios while maintaining voice clarity.