Jump to content

Quantization (image processing): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
ClueBot (talk | contribs)
m Reverting possible vandalism by 160.33.66.121 to version by 209.203.104.2. False positive? Report it. Thanks, ClueBot. (531709) (Bot)
m add WP:TEMPLATECAT to remove from template; genfixes
 
(33 intermediate revisions by 28 users not shown)
Line 1: Line 1:
{{Short description|Lossy compression technique}}
'''Quantization''', involved in [[image processing]], is a [[lossy compression]] technique achieved by compressing a range of values to a single quantum value. When the number of discrete symbols in a given stream is reduced, the stream becomes more compressible. For example, reducing the number of colors required to represent a digital [[image]] makes it possible to reduce its file size. Specific applications include [[Discrete cosine transform|DCT]] data quantization in [[JPEG]] and [[Discrete wavelet transform|DWT]] data quantization in [[JPEG 2000]].
{{More citations needed|date=November 2012}}
__FORCETOC__

'''Quantization''', involved in [[image processing]], is a [[lossy compression]] technique achieved by compressing a range of values to a single quantum (discrete) value. When the number of discrete symbols in a given stream is reduced, the stream becomes more compressible. For example, reducing the number of colors required to represent a digital [[image]] makes it possible to reduce its file size. Specific applications include [[Discrete cosine transform|DCT]] data quantization in [[JPEG]] and [[Discrete wavelet transform|DWT]] data quantization in [[JPEG 2000]].

== Color quantization ==
== Color quantization ==
{{mainarticle|Color quantization}}
{{main|Color quantization}}


Color quantization reduces the number of colors used in an image; this is important for displaying images on devices that support a limited number of colors and for efficiently compressing certain kinds of images. Most bitmap editors and many operating systems have built-in support for color quantization. Popular modern color quantization algorithms include the nearest color algorithm (for fixed palettes), the [[Median cut|median cut algorithm]], and an algorithm based on [[octree]]s.
Color quantization reduces the number of colors used in an image; this is important for displaying images on devices that support a limited number of colors and for efficiently compressing certain kinds of images. Most bitmap editors and many operating systems have built-in support for color quantization. Popular modern color quantization algorithms include the nearest color algorithm (for fixed palettes), the [[Median cut|median cut algorithm]], and an algorithm based on [[octree]]s.


It is common to combine color quantization with [[dither|dithering]] to create an impression of a larger number of colors and eliminate [[colour banding|banding]] artifacts.
It is common to combine color quantization with [[dither]]ing to create an impression of a larger number of colors and eliminate [[colour banding|banding]] artifacts.

== Grayscale quantization ==
Grayscale quantization, also known as gray level quantization, is a process in digital image processing that involves reducing the number of unique intensity levels (shades of gray) in an image while preserving its essential visual information. This technique is commonly used for simplifying images, reducing storage requirements, and facilitating processing operations. In grayscale quantization, an image with ''N'' intensity levels is converted into an image with a reduced number of levels, typically ''L'' levels, where ''L''<''N''. The process involves mapping each pixel's original intensity value to one of the new intensity levels. One of the simplest methods of grayscale quantization is uniform quantization, where the intensity range is divided into equal intervals, and each interval is represented by a single intensity value. Let's say we have an image with intensity levels ranging from 0 to 255 (8-bit grayscale). If we want to quantize it to 4 levels, the intervals would be [0-63], [64-127], [128-191], and [192-255]. Each interval would be represented by the midpoint intensity value, resulting in intensity levels of 31, 95, 159, and 223 respectively.

The formula for uniform quantization is:

<math>Q(x) = \left \lfloor \frac{x}{\Delta} \right \rfloor \times \Delta + \frac{\Delta}{2} </math>
Where:

* ''Q''(''x'') is the quantized intensity value.
* ''x'' is the original intensity value.
* Δ is the size of each quantization interval.

Let's quantize an original intensity value of 147 to 3 intensity levels.

Original intensity value: ''x''=147

Desired intensity levels: ''L''=3

We first need to calculate the size of each quantization interval:

<math>\Delta = \frac{255}{L-1} = \frac{255}{3-1} = 127.5</math>

Using the uniform quantization formula:

<math>Q(x) = \left \lfloor \frac{147}{127.5} \right \rfloor \times 127.5 + \frac{127.5}{2}</math>

<math>Q(x) = \left \lfloor 1.15294118 \right \rfloor \times 127.5 + \frac{127.5}{2}</math>

<math>Q(x) = 1 \times 127.5 + 63.75 = 191.25</math>

Rounding 191.25 to the nearest integer, we get <math>Q(x) = 191</math>

So, the quantized intensity value of 147 to 3 levels is 191.


== Frequency quantization for image compression ==
== Frequency quantization for image compression ==


The human eye is fairly good at seeing small differences in [[brightness]] over a relatively large area, but not so good at distinguishing the exact strength of a high frequency brightness variation. This fact allows one to get away with a greatly reduced amount of information in the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. This is the main lossy operation in the whole process. As a result of this, it is typically the case that many of the higher frequency components are rounded to zero, and many of the rest become small positive or negative numbers.
The human eye is fairly good at seeing small differences in [[brightness]] over a relatively large area, but not so good at distinguishing the exact strength of a high frequency (rapidly varying) brightness variation. This fact allows one to reduce the amount of information required by ignoring the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. This is the main lossy operation in the whole process. As a result of this, it is typically the case that many of the higher frequency components are rounded to zero, and many of the rest become small positive or negative numbers.

As human vision is also more sensitive to [[luminance]] than [[chrominance]], further compression can be obtained by working in a non-RGB color space which separates the two (e.g., [[YCbCr]]), and quantizing the channels separately.<ref name="wiseman">John Wiseman, ''An Introduction to MPEG Video Compression'', https://web.archive.org/web/20111115004238/http://www.john-wiseman.com/technical/MPEG_tutorial.htm</ref>


=== Quantization matrices ===
=== Quantization matrices ===


A typical video codec works by breaking the picture into discrete blocks (8×8 pixels in the case of MPEG<ref name="wiseman"/>). These blocks can then be subjected to [[discrete cosine transform]] (DCT) to calculate the frequency components, both horizontally and vertically.<ref name="wiseman"/> The resulting block (the same size as the original block) is then pre-multiplied by the quantization scale code and divided element-wise by the quantization matrix, and rounding each resultant element. The quantization matrix is designed to provide more resolution to more perceivable frequency components over less perceivable components (usually lower frequencies over high frequencies) in addition to transforming as many components to 0, which can be encoded with greatest efficiency. Many video encoders (such as [[DivX]], [[Xvid]], and [[3ivx]]) and compression standards (such as [[MPEG-2]] and [[H.264/AVC]]) allow custom matrices to be used. The extent of the reduction may be varied by changing the quantizer scale code, taking up much less bandwidth than a full quantizer matrix.<ref name="wiseman"/>
A quantization matrix is used in combination with a DCT coefficient matrix to carry out the previously mentioned transformation. Quantization matrices are often specifically designed to keep certain frequencies in the source to avoid losing image quality. Many video encoders, such as [[DivX]], [[Xvid]], [[3ivx]] and [[H.264/AVC]] allow custom matrices to be used.


This is an example of DCT coefficient matrix: <!--NOTE: this matrix was generated using random numbers and the other two matricies. It may not actually work well with an iDCT. -->
This is an example of DCT coefficient matrix: <!--NOTE: this matrix was generated using random numbers and the other two matricies. It may not actually work well with an iDCT. -->
Line 31: Line 70:
</math>
</math>


A common quantization matrix is: <!-- A source for the "common" justification would be nice. Wiseman gives the default MPEG matrix, which varies from the one below. -->
A common quantization matrix is:


:<math>
:<math>
Line 46: Line 85:
</math>
</math>


Using this quantization matrix with the DCT coefficient matrix from above results in:
Dividing the DCT coefficient matrix element-wise with this quantization matrix, and rounding to integers results in:


:<math>
:<math>
Line 73: Line 112:
-25.9375
-25.9375
\right)
\right)
=
=-26
-26
</math>
</math>


Typically this process will result in matrices with values primarily in the upper left (low frequency) corner. By using a zig-zag ordering to group the non-zero entries and [[run length encoding]], the quantized matrix can be much more efficiently stored than the non-quantized version.<ref name="wiseman"/>

==See also==
* [[Image segmentation]]
* [[Image-based meshing]]
* [[Range segmentation]]


==References==
{{Compression Methods}}
{{reflist}}<ref>{{Cite book |last=Smith |first=Steven W. |title=Digital signal processing: a practical guide for engineers and scientists |date=2003 |publisher=Newnes |isbn=978-0-7506-7444-7 |series=Demystifying technology series |location=Amsterdam Boston}}</ref>{{Compression Methods}}


{{DEFAULTSORT:Quantization (Image Processing)}}
[[Category:Lossy compression algorithms]]
[[Category:Lossy compression algorithms]]
[[Category:Image compression]]
[[Category:Data compression]]

Latest revision as of 00:53, 6 December 2024

Quantization, involved in image processing, is a lossy compression technique achieved by compressing a range of values to a single quantum (discrete) value. When the number of discrete symbols in a given stream is reduced, the stream becomes more compressible. For example, reducing the number of colors required to represent a digital image makes it possible to reduce its file size. Specific applications include DCT data quantization in JPEG and DWT data quantization in JPEG 2000.

Color quantization

[edit]

Color quantization reduces the number of colors used in an image; this is important for displaying images on devices that support a limited number of colors and for efficiently compressing certain kinds of images. Most bitmap editors and many operating systems have built-in support for color quantization. Popular modern color quantization algorithms include the nearest color algorithm (for fixed palettes), the median cut algorithm, and an algorithm based on octrees.

It is common to combine color quantization with dithering to create an impression of a larger number of colors and eliminate banding artifacts.

Grayscale quantization

[edit]

Grayscale quantization, also known as gray level quantization, is a process in digital image processing that involves reducing the number of unique intensity levels (shades of gray) in an image while preserving its essential visual information. This technique is commonly used for simplifying images, reducing storage requirements, and facilitating processing operations. In grayscale quantization, an image with N intensity levels is converted into an image with a reduced number of levels, typically L levels, where L<N. The process involves mapping each pixel's original intensity value to one of the new intensity levels. One of the simplest methods of grayscale quantization is uniform quantization, where the intensity range is divided into equal intervals, and each interval is represented by a single intensity value. Let's say we have an image with intensity levels ranging from 0 to 255 (8-bit grayscale). If we want to quantize it to 4 levels, the intervals would be [0-63], [64-127], [128-191], and [192-255]. Each interval would be represented by the midpoint intensity value, resulting in intensity levels of 31, 95, 159, and 223 respectively.

The formula for uniform quantization is:

Where:

  • Q(x) is the quantized intensity value.
  • x is the original intensity value.
  • Δ is the size of each quantization interval.

Let's quantize an original intensity value of 147 to 3 intensity levels.

Original intensity value: x=147

Desired intensity levels: L=3

We first need to calculate the size of each quantization interval:

Using the uniform quantization formula:

Rounding 191.25 to the nearest integer, we get

So, the quantized intensity value of 147 to 3 levels is 191.

Frequency quantization for image compression

[edit]

The human eye is fairly good at seeing small differences in brightness over a relatively large area, but not so good at distinguishing the exact strength of a high frequency (rapidly varying) brightness variation. This fact allows one to reduce the amount of information required by ignoring the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. This is the main lossy operation in the whole process. As a result of this, it is typically the case that many of the higher frequency components are rounded to zero, and many of the rest become small positive or negative numbers.

As human vision is also more sensitive to luminance than chrominance, further compression can be obtained by working in a non-RGB color space which separates the two (e.g., YCbCr), and quantizing the channels separately.[1]

Quantization matrices

[edit]

A typical video codec works by breaking the picture into discrete blocks (8×8 pixels in the case of MPEG[1]). These blocks can then be subjected to discrete cosine transform (DCT) to calculate the frequency components, both horizontally and vertically.[1] The resulting block (the same size as the original block) is then pre-multiplied by the quantization scale code and divided element-wise by the quantization matrix, and rounding each resultant element. The quantization matrix is designed to provide more resolution to more perceivable frequency components over less perceivable components (usually lower frequencies over high frequencies) in addition to transforming as many components to 0, which can be encoded with greatest efficiency. Many video encoders (such as DivX, Xvid, and 3ivx) and compression standards (such as MPEG-2 and H.264/AVC) allow custom matrices to be used. The extent of the reduction may be varied by changing the quantizer scale code, taking up much less bandwidth than a full quantizer matrix.[1]

This is an example of DCT coefficient matrix:

A common quantization matrix is:

Dividing the DCT coefficient matrix element-wise with this quantization matrix, and rounding to integers results in:

For example, using −415 (the DC coefficient) and rounding to the nearest integer

Typically this process will result in matrices with values primarily in the upper left (low frequency) corner. By using a zig-zag ordering to group the non-zero entries and run length encoding, the quantized matrix can be much more efficiently stored than the non-quantized version.[1]

See also

[edit]

References

[edit]

[1]

  1. ^ Smith, Steven W. (2003). Digital signal processing: a practical guide for engineers and scientists. Demystifying technology series. Amsterdam Boston: Newnes. ISBN 978-0-7506-7444-7.