ECE 576 - Engineering of Computer Based Systems: JPEG Image Compression

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

1

ECE 576 - Engineering of Computer Based Systems


J PEG Image Compression
*Thanks to Greg Stitt for providing/assembling much of the included information.
2
J PEG Image Compression
Color Transform
J PEG capable of using any color model
RGB, HSI, CMY, YUV, YCbCr
RGB, HSI, CMY spread useful visual information across 3 components
Hard to select information to discard
In YCbCr, most of useful information is in Y space
Some of Cb and Cr can be discarded
J PEG can transform color model to improve compression
3
J PEG Image Compression
RGB vs. YCbCr
RGB
R Red
G Green
B Blue
YCbCr
Y Luma (Brightness)
Cb Cb Chroma (Blue minus Luma)
Cr Cr Chroma (Red minus Luma)
Luma - Amount of light that passes through or is emitted from a
particular area
Chroma - Difference between a color and a chosen reference color of the
same luminous intensity
4
J PEG Image Compression
RGB vs. YCbCr
RGB
YCbCr
5
J PEG Image Compression
Down Sampling
Luminance more important than chrominance
Store less information for chrominance
Example: 1000x1000 image
Store 1000x1000 luminance pixels
Store 500x500 chrominance pixels
Each chrominance pixel corresponds to actual 2x2 block
=> Each 2x2 block requires 6 pixels instead of 12
6
J PEG Image Compression
DCT Discrete Cosine Transform
Convert spatial/time domain to frequency
domain
Time domain plots how some value
changes over time
Frequency domain decomposes signal from
time domain into sine and cosine waves
with various amplitudes
Spatial frequency
The frequency over distance (instead of
time)
The frequency domain is a space in which
the value at each image position
represents the amount that the intensity
values in the image vary over a specific
distance
Any image can be formed by adding
different spatial frequencies
7
J PEG Image Compression
Frequency Domain
8
J PEG Image Compression
DCT Discrete Cosine Transform
Output of DCT is array of DCT coefficients representing
different strengths of each frequency
For J PEG, DCT is done on 8x8 blocks
8x8 DCT coefficients
Top left is low frequencies
(0,0) is DC value, or average, of all pixels
Bottom right is strength of cosine wave alternating from
max to min every pixel
9
J PEG Image Compression
DCT Discrete Cosine Transform
DCT Equation:
D[x,y] = original pixel value at location x, y
F(u,v) = output coefficient at location x, y
10
J PEG Image Compression
DCT Discrete Cosine Transform
DCT operates on 8x8 blocks,
u, v, x, and y only range in value from 0 to 7
Precompute 64 possible cosine values and store in an 8x8 table,
Rewrite DCT Equation:
D[x,y] = original pixel value at location x, y
F(u,v) = output coefficient at location x, y
11
J PEG Image Compression
DCT Discrete Cosine Transform
Reason for using DCT
Important to separate frequencies because human eye is more
sensitive to low frequency information
Can discard some of high-frequency information
12
J PEG Image Compression
Quantization
Divides each DCT coefficient by some value to reduce total number of
bits
Many of the high frequency coefficients become 0
Other information is lost from integer division
This is where the loss is J PEG comes from
.. .. 12 31
16 15 59 42 32 12 32 42
12 94 21 35 23 67 2 49
19 12 23 12 76 32 74 62
32 12 53 14 23 45 62 89
/
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 1
0 0 0 0 0 1 1 1
=
13
J PEG Image Compression
Quantization
Different Types
Constant amount
Varying amount for different frequencies
Separate values for luminance and chrominance
Larger amount for chrominance
Quantization table stored in J PEG file
Generally a sample table is used
Different Quality jpegs use different quantization tables
14
J PEG Image Compression
Quantization
Example quantization tables:
15
J PEG Image Compression
Quantization
Qual = 100
Size = 60.8 KB
Qual = 75
Size = 12.8 KB
Qual = 50
Size = 6.9 KB
16
J PEG Image Compression
Quantization
Qual = 25
Size = 2.6 KB
Qual = 10
Size = 1.8 KB
Qual = 1
Size = 1.6 KB
17
J PEG Image Compression
Encoding
After quantization, many DCT coefficients are 0, especially for high
frequencies
High frequencies appear in bottom right of 8x8 block
Grouping these 0s together makes compression better
Zig-zag converts 8x8 block into 16x1, in the following order:
18
J PEG Image Compression
Encoding
Run length encoding
For each non-zero DCT coefficient, J PEG records the number of
zeros that preceded the number, the number of bits needed to
represent the number's amplitude, and the amplitude itself.
19
J PEG Image Compression
Encoding
After run length encoding, Huffman encoding further
compresses the 8x8 block
After compression, block is written to file along with end
of block marker
20
J PEG Image Decompression
Basically opposite of encode
Decompress, Dequantize, Inverse DCT, Up-sampling, color
transform

You might also like