Compression

Compression Ratios

How to measure compression effectiveness and quality trade-offs.

Evaluating compression with three criteria

Compression effectiveness is measured against the input data and the goal of the application. Algorithms differ in how they exploit repetition, how much computation they require, and how they affect the reconstructed result. Selecting a method requires objective measurements together with criteria based on user perception.

Three primary criteria are size reduction, encoding and decoding speed, and the quality of the reconstructed result. Size and time can be measured directly, while perceptual quality requires observers or a quality model. These metrics describe the quantities and the relationship between file size and quality. A measurement should use the same input set, output format, and hardware conditions. Results from different files may have different practical value even when their ratios match.

Metric 1. Size reduction

One goal of compression is to reduce the number of bytes needed to store data. Several related measures describe the reduction, since a size ratio and a percentage saved express the same result on different scales.

Compression Ratio

A common measure is the . The quotient shows how many times the input size exceeds the compressed stream size.

Compression Ratio=Uncompressed SizeCompressed Size\text{Compression Ratio} = \frac{\text{Uncompressed Size}}{\text{Compressed Size}}

Assume a raw image has a size of 100 megabytes (MB). After lossless compression with PNG, the resulting file is 40 MB. The compression ratio is:

100 MB40 MB=2.5\frac{100 \text{ MB}}{40 \text{ MB}} = 2.5

The result is written as 2.5:1. The input is 2.5 times larger than the compressed stream. The same 100 MB image might have a compressed size of 10 MB with a lossy method such as JPEG. The ratio is then:

100 MB10 MB=10\frac{100 \text{ MB}}{10 \text{ MB}} = 10

The result is 10:1. A higher ratio means a greater reduction in this size measurement. The ratio alone says nothing about execution time or image quality. Format headers, metadata, and reconstruction cost also matter when formats are compared. For very small files, overhead can change the ratio substantially.

Percentage reduction

Percentage reduction describes the share of the initial size that no longer needs to be stored after compression. It is useful when comparing the same input range.

Percentage Reduction=(1−Compressed SizeUncompressed Size)×100%\text{Percentage Reduction} = \left(1 - \frac{\text{Compressed Size}}{\text{Uncompressed Size}}\right) \times 100\%

For the JPEG example with sizes of 100 MB and 10 MB:

(1−10 MB100 MB)×100%=(1−0.1)×100%=0.9×100%=90%\left(1 - \frac{10 \text{ MB}}{100 \text{ MB}}\right) \times 100\% = (1 - 0.1) \times 100\% = 0.9 \times 100\% = 90\%

A 10:1 ratio corresponds to a 90% size reduction. Both metrics describe the same outcome and support different comparisons.

Average bits per symbol

This measure connects a size result with the limit described by information theory. It gives the average number of bits used to represent one data unit, or symbol. A symbol can be a text character, an image pixel, or an audio waveform sample.

An RGB image with 8 bits per channel has 24 bits per pixel. If lossless PNG compression gives an average of 14.5 bits per pixel, that is the measured rate of 14.5 bits per symbol under this model. It can be compared with the of the source when the same symbol model is used. The ratio depends on whether symbols mean pixels, color components, filtered samples, or bytes in the PNG stream. The comparison is meaningful only when the unit and modeling order are specified consistently.

Metric 2. Speed and resources

A high compression ratio has limited practical value if encoding one file takes several days. Processing time matters in streaming and other real-time applications. Two basic measurements are used:

  • Compression speed: The time needed to process input and produce a compressed stream. It matters for live video, where data is encoded before transmission, and for archiving large collections.
  • Decompression speed: The time needed to reconstruct data from a compressed stream. In a service where a file is encoded once and read many times, decoding speed can matter more. This includes webpage images and high-definition video playback.

Compression ratio and processing time are usually linked to computational cost. bzip2 and LZMA or LZMA2 selected as methods in a 7z archive can achieve better ratios than gzip's Deflate with settings focused on size, while the settings also affect compression time, decompression time, and memory use. A large RAM requirement can limit use on smartphones or embedded systems. A practical benchmark should measure both directions separately because an encoder may use much more memory than a decoder. Streaming applications also care about the delay before the first output block.

Metric 3. Quality in lossy compression

With lossless compression, the result can be checked against the input. With lossy compression, evaluation must describe the distortion and its effect on perception. The result depends on the data, viewing conditions, and application goal.

Subjective Quality Assessment

collects observer ratings of perceived image, audio, or video quality.

One method is the Mean Opinion Score (MOS) test. In a controlled procedure, observers rate material using a specified scale. Depending on the test, they may see a reference version, several variants, or only the test material. A 1 (bad) to 5 (excellent) scale is common, and the mean gives the MOS value.

MOS directly collects perceptual ratings, while the result depends on the observers, material, and test conditions. A study takes time and resources. Presentation can be automated, while the ratings themselves still require observers. MOS is a mean for a particular procedure and group. It should not be treated as a fixed quality value for every display, viewing distance, or content type.

Objective quality assessment

uses a formula or model to compare the original signal with the reconstructed signal.

A foundational metric is Mean Squared Error (MSE). It is the average of squared differences between original and reconstructed data points, such as pixel values. MSE is easy to calculate, while its scale is not directly perceptual.

Peak Signal-to-Noise Ratio (PSNR) is derived from MSE and reported on a logarithmic decibel (dB) scale. The scale helps compare errors of different magnitudes, while it is not a complete perceptual model.

PSNR=10⋅log⁡10(MAXI2MSE)PSNR = 10 \cdot \log_{10}\left(\frac{MAX_I^2}{MSE}\right)

MAXIMAX_I is the maximum possible data-point value, for example 255 for an 8-bit pixel. A higher PSNR value indicates a smaller MSE for the same signal range. Artifact visibility depends on the signal range, content, and viewing conditions, so no single PSNR threshold determines it universally. PSNR measures mathematical error and can miss artifacts that matter to observers. SSIM (Structural Similarity Index Measure) is therefore also used to compare local luminance, contrast, and structure. Both metrics require aligned original and reconstructed images. A change in resolution, color space, or sample range can change the score without changing the subjective judgment.

Lossy compression artifacts

With strong lossy compression, discarded components can become visible or audible. These distortions are called .

Adjust the slider to see how JPEG quality settings affect file size and the visibility of artifacts.

Common artifacts include:

  • Blocking (Blockiness): The most common artifact in DCT-based compression (like JPEG). The image appears to be divided into a grid of 8x8 pixel blocks, as the compression for each block is handled independently and the discontinuities at the block edges become visible.
  • Ringing (or Mosquito Noise): Appears as ghostly halos or noise around sharp edges and contours in an image. It is caused by the inaccurate representation of high-frequency components that define those edges.
  • Blurring: The loss of fine details and textures, making the image appear soft or out of focus. This is a direct result of aggressive quantization of high-frequency coefficients.
  • Color Banding (Posterization): Smooth gradients of color are replaced with distinct bands or steps of solid color. This happens when the number of available colors is drastically reduced. This is a common artifact in GIF files with too few colors in the palette.

Adjust the palette size to see how fewer colors introduce banding and remove smooth tonal transitions.

Results should use the same input material and encoder settings. A profile change can affect size, time, and quality.

Balancing size, time, and quality

Evaluation covers compression ratio, speed, and quality. Increasing compression can reduce the file while changing computation time or quality. Archiving may prefer slow encoding and a high lossless ratio. Video chat needs low latency, stable decoding, and quality suitable for conversation. Professional photography may accept a larger file to preserve detail. A benchmark should record input and output bytes, wall-clock time, CPU time, and memory use. For images and video, it should also state resolution, color space, and how samples were aligned. These details make measurements repeatable and explain differences between implementations. For effectively incompressible data, the ratio can fall below 1 when headers and markers increase the output. This is common for small inputs, so the ratio alone should not determine the format choice. A network application also cares about the latency of the first fragment. The percentage must be interpreted with the same baseline: a ratio of 1:1 means no size change, while a ratio of 2:1 means output is half the input. Lossy settings should be compared on identical source material and with a stated decoder or display condition. A metric measured after a color conversion can hide artifacts introduced earlier in the pipeline. MOS results describe a tested group and procedure, not a permanent property of a codec. When a service chooses a setting, it can combine ratio, transfer time, decoding cost, and an application-specific quality threshold. Separate results for encoding and decoding also prevent an asymmetric workload from being hidden.

Related articles