Unit4
Unit4
o High-resolution images can occupy a large amount of memory or storage space. Image compression
reduces the file size, allowing you to store more images in the same storage capacity. This is
particularly important for applications that generate a large number of images, such as digital
photography or satellite imaging.
2. Faster Transmission:
o Compressed images require less bandwidth for transmission over networks, which is crucial for tasks
like sending images over the internet, streaming media, or in video conferencing. Smaller image sizes
result in faster upload and download times, improving user experience and reducing transmission
costs.
3. Efficient Processing:
o Smaller images are easier and faster to process since they require less computational power and
memory. This is important for real-time applications such as image processing, computer vision tasks,
and machine learning algorithms, where high-speed processing is necessary. Additionally, it helps in
reducing the overall resource usage, making the system more efficient.
Spatial redundancy refers to the repetition of similar or identical pixel values in an image, especially in regions that
do not undergo significant changes in intensity or color. This redundancy can be exploited during compression to
reduce the amount of data required to represent the image. In other words, spatial redundancy occurs when
neighboring pixels have similar values, allowing for more efficient storage by encoding these patterns rather than
storing each pixel individually.
For example, large areas of solid color or smooth gradients often exhibit high spatial redundancy, which makes them
prime candidates for compression techniques like run-length encoding or transform coding (e.g., JPEG).
Objective fidelity refers to the measure of how accurately a compressed image represents the original image without
perceptual distortion. It is a quantitative approach to evaluating the quality of the compressed image based on
factors such as:
• Compression Ratio: The ratio of the original image size to the compressed size.
• Error Metrics: Objective fidelity can be assessed using error metrics like Peak Signal-to-Noise Ratio (PSNR) or
Mean Squared Error (MSE), which quantify the difference between the original and compressed images.
Objective fidelity is important because it helps to evaluate the effectiveness of an image compression technique in
preserving the quality of the image after compression.
The image compression model involves several stages to reduce the size of the image while maintaining as much
visual quality as possible. Below is a simplified block diagram and the steps involved in the process:
Block Diagram:
Steps Involved:
1. Preprocessing: The image is first preprocessed, which may include operations like converting the image to
grayscale, reducing noise, or normalizing the pixel values.
2. Transformation: In this step, the image is transformed into a different domain (e.g., from the spatial domain
to the frequency domain). A common transformation used is the Discrete Cosine Transform (DCT) in JPEG
compression. The purpose is to represent the image in a form that is easier to compress.
3. Quantization: After transformation, the image coefficients are quantized to reduce the precision of the
values, which leads to a reduction in data size. The higher the quantization level, the greater the
compression, but it can also lead to a loss in image quality.
4. Encoding (Entropy Coding): This step involves encoding the quantized values using efficient methods like
Huffman coding or Arithmetic coding. These methods assign shorter codes to frequently occurring values and
longer codes to less frequent values, reducing the overall data size.
5. Compressed Image: The final compressed image is obtained, which can be stored or transmitted.
1. JPEG (Joint Photographic Experts Group): A commonly used format for lossy image compression, especially
for photographs.
2. PNG (Portable Network Graphics): A lossless image format that supports transparency and is widely used for
web images.
3. GIF (Graphics Interchange Format): A lossless format for images with limited color depth, often used for
simple graphics or animations.
4. TIFF (Tagged Image File Format): A versatile image format that supports both lossless compression and high-
quality images, used in professional photography and scanning.
The JPEG (Joint Photographic Experts Group) standard is widely used for compressing continuous-tone still images,
such as photographs, by applying a lossy compression method. Here's a brief explanation of how it works:
o This step is beneficial because the human eye is more sensitive to brightness details than to color
details, allowing more aggressive compression for the chrominance channels (Cb and Cr) without a
significant loss in perceived quality.
o The image is divided into small blocks, typically 8x8 pixels. Each block is then processed individually.
o A Discrete Cosine Transform (DCT) is applied to each block to convert the spatial domain into the
frequency domain. The DCT separates the image data into a set of frequencies: low frequencies
(representing major structures) and high frequencies (representing fine details or noise).
o The low-frequency components are most important for image quality, while high-frequency
components can often be discarded without significant visual loss.
3. Quantization:
o The DCT coefficients are quantized to reduce their precision, which is a major step in compressing
the image. A quantization table is used to reduce high-frequency components more aggressively,
taking advantage of human visual perception (since the eye is less sensitive to small variations in
high-frequency details).
o This quantization introduces some loss of image quality, but it significantly reduces the amount of
data needed to represent the image.
o After quantization, the DCT coefficients are encoded using Huffman coding or Arithmetic coding to
further compress the data.
o These techniques assign shorter codes to more frequent values and longer codes to less frequent
values, reducing the total size of the data.
5. Compression Output:
o The final compressed image consists of the encoded DCT coefficients, along with other data such as
header information, which specifies the image dimensions, quantization tables, and other
parameters necessary for decoding.
o The result is a compressed image file, typically with a significant reduction in size compared to the
original image, with some loss of detail due to quantization.
JPEG compression is widely used in applications where some loss of quality is acceptable in exchange for reduced file
size, such as in web images, digital photography, and image archives.
1. Huffman Coding Algorithm (5):
Huffman coding is a lossless data compression algorithm that assigns variable-length codes to input characters, with
shorter codes assigned to more frequent characters.
Algorithm:
o Analyze the input string and calculate the frequency of each character.
o Create a min-heap (priority queue) where each node contains a character and its frequency.
▪ Create a new internal node with these two nodes as children, and assign it a frequency equal
to the sum of the frequencies of the two nodes.
o Starting from the root of the Huffman tree, assign a binary code to each character by traversing the
tree.
o Assign ‘0’ for the left branch and ‘1’ for the right branch.
o Replace each character in the original input with its corresponding Huffman code to get the
compressed output.
Golomb coding is a lossless data compression algorithm, particularly useful for encoding integer sequences with
known or estimated geometric distribution.
Algorithm:
o Golomb coding uses a parameter mmm, where mmm is typically chosen based on the distribution of
the data. For most practical uses, mmm can be approximated as the mean of the data or another
value that minimizes the average code length.
o For each integer xxx, divide it by mmm to get the quotient qqq and remainder rrr.
o x=q⋅m+rx = q \cdot m + rx=q⋅m+r, where qqq is the quotient, and rrr is the remainder.
o The quotient qqq is encoded in unary form (i.e., using qqq number of 1's followed by a 0).
o Concatenate the unary code for the quotient and the binary code for the remainder to generate the
Golomb code for each integer.
LZW (Lempel-Ziv-Welch) is a lossless data compression algorithm that replaces strings of characters with shorter
codes.
Algorithm:
o Create a dictionary with all individual characters of the input data and assign them a unique code.
o Read the input data and start with the first character.
o Look for the longest substring that already exists in the dictionary.
o Add the next character to the substring and add this new substring to the dictionary with a new
code.
o Continue reading characters and adding new substrings to the dictionary until the entire input is
processed.
Arithmetic coding is a form of entropy encoding that represents an entire message as a single number, a fraction
between 0 and 1, which is then encoded into binary.
Algorithm:
o Calculate the probability of each symbol in the input message (or use a predefined model if
necessary).
o For each symbol in the input message, update the range according to the probability of the symbol.
This divides the range into sub-ranges corresponding to the symbols.
o Update the low and high values by narrowing down the range based on the probability of the
symbol.
o Once all symbols are processed, the final range [low, high] will represent the entire message. Any
number in this range can be used as the compressed code.
Run-Length Encoding (RLE) is a simple form of lossless data compression that encodes sequences of identical data
elements into a single data value and count.
Algorithm:
1. Step 1: Initialize
o Traverse the data and identify runs of consecutive identical symbols (characters or pixels).
o For each run, output the symbol and the length of the run. For example, a run of "AAAA" would be
encoded as "A 4".
o Continue processing the input data, identifying runs of identical characters or symbols, and
outputting them until the entire input is processed.
o The output will be a sequence of pairs representing the symbol and the count for each run.