0% found this document useful (0 votes)
86 views

Chapter 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Chapter 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

Chapter 8

Image Compression
Image Compression
Data and Information
• Data and information
– Data are means by which information is conveyed
– Various amount of information may be needed to
represent the same amount of information
– Suppose information of interest is story; words are used
to relate the information
– If two individuals use a different number of words to tell
the same story, two different versions of the story are
created, and at least one includes nonessential data.
• One contains data (or words) that either provide no relevant
information or simply restate that which is already known. It is
called redundancy.
Data Redundancy and
Compression
• Data redundancy
– Relative data redundancy RD for the data set n1

1 n1
RD = 1- CR =
CR n2
– CR: compression ratio
– n1, n2: number of information carrying units in two data
sets that represent the same information
– Compression ratio, 10 (or 10:1) means that first data set
has 10 information carrying units for every 1 unit in
second or compressed data set.
• First data set has 90% redundant data
• Data compression
– Reducing the amount of data required to represent a
given quantity of information
Data Redundancy
In digital image compression, three basic
data redundancy:
– Coding redundancy
– Interpixel redundancy
– Psychovisual redundancy
Coding Redundancy
• In most images, certain gray levels are more
probable than others
• Assigning fewer bits to the more probable
gray levels to the less probable ones
achieves data compression, called variable-
length coding.
• If the gray levels of an image are coded in a
way that uses more code symbols than
absolutely necessary to represent each gray
level,
– the resulting image has coding redundancy.
Coding Redundancy - Example
nk
pr (rk ) =
n
L -1
Lavg = å l (rk ) pr (rk )
k =0

Lavg = 2(0.19) + 2(0.25) + 2(0.21) + 3(0.16) + 4(0.08) + 5(0.06) + 6(0.03)


+ 6(0.02) = 2.7bits
Interpixel Redundancy
• A pixel value can be
predicted based its
neighbors.
• Include spatial redundancy,
geometric redundancy,
inter-frame redundancy
Interpixel Redundancy - Example

Autocorrelation
Coefficients by
Eq 8.1-6
Any given pixel
can be
predicted from
its neighbors
Psychovisual Redundancy
• The eye does not respond with equal
sensitivity to all visual information.
Certain information simply has less
relative importance than other information
in normal visual processing
• In general, an observer searches for
distinguishing features such as edges
or textural regions and mentally combines
them into recognizable groupings.
Psychovisual Redundancy

https://slideplayer.com/slide/12988598/
Psychovisual Redundancy

Table 8.2

Improved Gray Scale Quantization (IGS)


Human eye is sensitive to edge.
à Add a pseudo-random number before quantization.
Evaluation Metrics
• Fidelity criteria
• Measure information
– Entropy
Fidelity Criteria
• Objective fidelity criteria
– Root-mean-square error (erms)
1/ 2

åå [ ]
é 1 M -1 N -1
ˆf (x, y ) - f (x, y ) 2 ù
erms =ê ú
ë MN x =0 y =0 û
– Mean-square signal-to-noise ratio (SNRms)
åå [ ]
M -1 N -1
ˆf ( x, y ) 2
x =0 y =0
SNRms =
åå [ ]
M -1 N -1
ˆf ( x, y ) - f ( x, y ) 2
x =0 y =0
– Root-mean-square SNRms (SNRrms)
Fidelity Criteria
Chapter 8
Image Compression
Image Compression model

• Source Encoder is used to remove redundancy in the


input image.
• Channel Encoder is used to introduce redundancy in a
controlled fashion to help combat noise. Example: Parity
bit.
• This provides a certain level of immunity from noise that
is inherent in any storage/transmission system. If the
channel is not prone to noise, this block maybe
eliminated.
Image Compression model
• The Channel could be a communication link or a
storage/retrieval system.

• Channel Decoder and Source Decoder invert the


operations of the corresponding encoder blocks.

• We will mainly concentrate on the source


encoder/decoder blocks and not on the channel
encoder/decoder steps.
Source Encoder

Source Encoder

• Source encoder is responsible for reducing or


eliminating any coding, interpixel, or psychovisual
redundancy.

• The first block “Mapper” transforms the input data into


a (usually nonvisual) format, designed to reduce
interpixel redundancy. This block is reversible and
may or may not reduce the amount of data. Example:
run-length encoding, image transform.
Source Encoder
• The Quantizer reduces accuracy of the mapper
output in accordance with some fidelity criterion. This
block reduces psychovisual redundancy and is
usually not invertible.

• The Symbol Encoder creates a fixed or variable


length codeword to represent the quantizer output
and maps the output in accordance with this code.
This block is reversible and reduces coding
redundancy.
Source Decoder

Source Decoder

• The decoder blocks are inverse operations of the


corresponding encoder blocks (except the quantizer
block, which is not invertible).
Measure Information
• Information is measured based on its probability
of occurrence
• A random event E that occurs with probability P(E)
is said to contain
1
I (E ) = log = - log P(E )
P (E )
units (bits) of information
– I(E): self-information of E
– The amount of self-information attributed to event E is
inversely related to the probability of E
– If base 2 is used, the unit of information is called a bit
– Example: if P(E) = ½, then I(E) = -log2P(E) = 1.
– Information is used to clear the uncertainty.
Entropy
• Average information per source output, or
uncertainty, or entropy of the source
H (z ) = -å P(a j )log P(a j )
J

j =1

• How to interpret the increase of entropy?


– The average amount of information obtained by
observing a single source output.
• What happens if the events are equally probable?
– The total entropy or uncertainty is maximized
– Average information per source symbol is maximized.
• For the coding, it represents the minimum bits per
symbol.
Example
• Estimate the information content (entropy)
of the following image (8 bit image):
21 21 21 95 169 243 243 243
If all the symbols are equally 21 21 21 95 169 243 243 243
probable, the entropy is 8bits/pixel 21 21 21 95 169 243 243 243
21 21 21 95 169 243 243 243
Gray - level Count Pr obability • First-order estimate of the entropy (bits/pixel)
21 12 3/8
95 4 1/ 8 - 3 / 8 * log 2(3 / 8) - 1 / 8 * log 2(1 / 8) - 1 / 8 * log 2(1 / 8) - 3 / 8 * log 2(3 / 8) = 1.81
169 4 1/ 8
• Second-order estimate of the entropy (bits
243 12 3/8
every two pixels)
Gray - level - pair Count Pr obability
-2/4*log2(1/4) -3/8*log2(1/8) -1/7*log2(1/7)=2.5/2symbols
(21,21) 8 1/ 4
2.5/2=1.25 bits/symbol
(21,95) 4 1/ 8
(95,169) 4 1/ 8
(169,243) 4 1/ 7 What do these two numbers tell you?
(243,243) 8 1/ 4
(243,21) 4 1/ 8
Applications of Information Theory
• Misinterpretation: increasing the transmission
rate of information over a communication channel
increased the probability of error (early 40s)
– Shannon proved that this is not true as long as the
communication rate was below channel capacity
• Information theory answers two fundamental
questions in communication theory:
– What is the ultimate data compression
• The entropy
– What is the ultimate transmission rate of
communication
• The channel capacity
Fidelity criteria to
measure performance

Data 3

Lossy
Information
Data 2

Lossless

Data 1

Data Data Measure


redundancy compression information
Compression Approaches
• Error-free compression or lossless
compression
– Variable-length coding (only reduce
code redundancy)
– Bit-plane coding
– Lossless predictive coding
• Lossy compression
– Lossy predictive coding
– Transform coding
Variable-length Coding
• Only reduce code redundancy
• Assign the shortest possible code
words to the most probable gray
levels
• Huffman coding
– Can obtain the optimal coding scheme
Revisit Example
rk pr (rk ) Code1 l1 (rk ) Code2
r0 = 0 0.19 000 3 00
r1 = 1 / 7 0.25 001 3 1
r2 = 2 / 7 0.21 010 3 0
r3 = 3 / 7 0.16 011 3 01
r4 = 4 / 7 0.08 100 3 10
r5 = 5 / 7 0.06 101 3 11
r6 = 6 / 7 0.03 110 3 000
r7 = 1 0.02 111 3 001
Huffman Coding
• Uniquely decodable
• Source reduction
– Order the probabilities of symbols
– Combine the lowest probability symbols
into a single symbol that replaces them
in the next source reduction
• Code each reduced source, starting
with the smallest source and working
back to the original source
Chapter 8
Image Compression
Chapter 8
Image Compression

011100010111 à a1 a2 a6 a5 a2
Entropy = -0.4log0.4-0.3log0.3-0.2*log0.1 - 0.06*log0.6
-0.04*log0.04= 2.14 bits/symbol
Theoretical lower limit

Hoffman code efficiency = 2.14/2.2=0.973


Problems with Huffman
Coding
• Optimal Binary Huffman code
requires large amount of
computations
• Variants(443 page)
– Truncated Huffman
– B2-code
– Binary shift
– Huffman shift
LZW
• Attack interpixel redundancy
• Coding book or code table
• Used in GIF, TIFF, PDF
• Coding book is created while the
data are being encoded
Example
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Example Cont.
Bit-plane Coding
• Attack inter-pixel redundancy
• First decompose the original image
into bit-plane
• Compress each binary image via
one of several well-known binary
compression methods
• Binary image compression approach
– run-length coding (RLC)
Chapter 8
Image Compression
Bit-plane Decomposition
• Bit-plane slicing
• Problem: small changes in gray level can have a
significant impact on the complexity of the bit
plane
– 127 vs. 128 è 0111 1111 vs. 1000 0000
• Solution: (m bit gray code)
g i = ai Å ai +1 0£i £ m-2
g m-1 = am-1
• Example:
– 127 è 0111 1111 è 0100 0000
– 128 è 1000 0000 è 1100 0000

https://www.youtube.com/watch?v=cF-Q5j7RUEw
https://www.youtube.com/watch?v=-qMm9hhvp9Y
Chapter 8
Image Compression
Binary Image Compression
- RLC
• Developed in 1950s
• Standard compression approach in FAX
coding
• Approach
– Code each contiguous group of 0’s or 1’s
encountered in a left to right scan of a row by
its length
– Establish a convention for determining the
value of the run
– Code black and white run lengths separately
using variable-length coding
https://api.video/what-is/run-length-encoding
Example
Original image 2 127 128
3 32 33

0000 0010 0111 1111 1000 0000


Binary code
0000 0011 0010 0000 0010 0001

0000 0011 0100 0000 1100 0000


XOR binary 0000 0010 0011 0000 0011 0001 Run-length coding
001 011 000 000 000 000 100 100 21 12 3 3 3 3 012 012
8 bit planes 000 000 011 011 000 000 100 001 3 3 12 12 3 3 012 21

1 0.34 (1) 0.66 (0) 3 1.00 (0) 0 0.34 (1) 1 2 0.4 (1) 0.6 (0)
Huffman
coding 2 0.33 (00) 0.34 (1) 1 0.33 (00) 2 2 0.4 (00) 0.4 (1)
3 0.33 (01) 2 0.33 (01) 0 1 0.2 (01)

001 100 01 01 0 0 10001 01100


Final code 01 01 100 100 0 0 10001 001
Lossless Predictive Coding
• Do not need to decompose image into bit planes
• Eliminate interpixel redundancy (closely spaced
pixels- in space and/or time)
• Code only the new information in each pixel.
• The new information is the difference between
the actual and predicted value of that pixel

e(x, y ) = f (x, y ) - fˆ (x, y ) linear combination of m previous


values
ˆf (x, y ) = round é m
ù
êåa i f (x, y - i )ú for images
ë i =1 û
• m is the order of predictor as a 𝑓 !
https://www.youtube.com/watch?v=V2QlhVWRV7E
https://www.youtube.com/watch?v=EvjrxnzI63Y
Example: Lossless Predictive
Coding
Example: Lossless Predictive
Coding
Example: Lossless Predictive
Decoding
Example 2: Lossless
Predictive Coding

https://www.youtube.com/watch?v=EvjrxnzI63Y
Example 2: Lossless
Predictive Coding

https://www.youtube.com/watch?v=EvjrxnzI63Y
Lossless Compression
Approaches
Averagely, use
Variable-length coding shorter-length
Code code to
redundancy Huffman coding convey the
same amount of
information

Bit-plane coding
Run-length coding
Interpixel
LZW
redundancy
Predictive coding
Lossy Compression
• Spatial domain methods
– Lossy predictive coding
• Delta modulation (DM)
• Transform coding
– Operate on the transformed image
Lossy Predictive Coding
• Prediction + quantization

Predictor fˆn = a f n -1

Error eˆ = f - fˆ
n n n

Delta
• ìd if en > 0
Error quantization en = í
î- d
Modulation
otherwise
• •

Prediction f n = e n + fˆn
Lossy Predictive Coding

fˆn = a f n -1
eˆ = f - fˆ
n n n

• ìd if en > 0
en = í
î- d otherwise
• •
f n = e n + fˆn

𝛼=1

𝑒 = 𝑓 − 𝑓ˆ
Transform Coding
• Use discrete image transforms to transform the
image
• Discard those coefficients that are near zero
• Coarsely quantize those coefficients that are small
• When reconstructed later, little important content
will have been lost
• Example
– JPEG (image lossy compression)
– MPEG (video compression)
– Wavelet transform
JPEG
• Joint Photographics Expert Group
• An image compression standard
sanctioned by ISO
• can be very effectively applied to a 24-bit
color image, achieving compression
ratios of 10:1 to 20:1 without any image
degradation that is visible to the human
eye at normal magnification
• File is saved as .jpg or .jpeg
JPEG Compression Steps
• Convert RGB model to intensity and chrominance
(YIQ)
• Throw away half of the chrominance data
• Divide the pictures into blocks of 8x8 pixels
• Perform a discrete Cosine transform on each
block
• Quantize the DCT coefficients
• Run-length encoding
• Huffman encoding
Color model Downsample Divide picture DCT on Huffman
conversion chrominance content into 8x8 blocks each block RLC
coding
JPEG Compression: Step 1
Step 1: The input image is divided into a small block which is
having 8x8 dimensions. This dimension is sum up to 64 units.
Each unit of the image is called pixel.

https://www.javatpoint.com/jpeg-compression
JPEG Compression: Step 2
Step 2: JPEG uses [Y,Cb,Cr] model instead of using the [R,G,B]
model. So in the 2nd step, RGB is converted into YCbCr.
The YIQ Color Space
• Used in US commercial color television broadcasting
• Recoding of RGB for transmission efficiency and for
downward compatibility with b/w television
• Y component: illuminance (gets the majority of the b/w)
• I, Q: chrominance

éY ù é0.299 0.587 0.114 ù é R ù


ê I ú = ê0.596 - 0.275 - 0.321ú êG ú
ê ú ê úê ú
êëQ úû êë0.212 - 0.523 0.311 úû êë B úû

• NTSC broadcast TV: 4.2MHz for Y, 1.5MHz for I, 0.55MHz


for Q
• VCR: 3.2MHz for Y, 0.63 MHz for I.
JPEG Compression: Step 3
Step 3:
• After the conversion of colours, it is forwarded to DCT.
• DCT uses a cosine function (Matrix) and does not use
complex numbers like DFT.
• It converts information which are in a block of pixels from the
spatial domain to the frequency domain.
Discrete Cosine Transform
N -1 N -1

• Forward transform T (u, v) = åå f ( x, y) g ( x, y, u, v)


x =0 y =0

é (2 x + 1)up ù é (2 y + 1)vp ù
g ( x, y, u, v) = a (u )a (v) cosê ú cosê ú
ë 2N û ë 2N û
N -1 N -1
• Inverse transform f ( x, y) = åå T (u, v)h( x, y, u, v)
x =0 y =0

g ( x, y, u, v) = h( x, y, u, v)
https://www.youtube.com/watch?v=h3u-lVDyHD4
https://www.geeksforgeeks.org/discrete-cosine-transform-algorithm-
program/
The 64 DCT Basis Functions
• Horizontal frequencies increase from left to right,
• and vertical frequencies increase from top to bottom.
v
0 1 2 3 4 5 6 7
0
u
1

https://www.mathworks.com/help/images/discrete-cosine-transform.html
JPEG Compression: Step 4
Step 4: Humans are unable to see important aspects of the
image because they are having high frequencies. The matrix
after DCT conversion can only preserve values at the lowest
frequency that to in certain point. Quantization is used to
reduce the number of bits per sample.
æ F (u, v) ö
Stqndard quantization formula: F ' (u, v) = round çç ÷÷
è q(u, v) ø
JPEG Compression: Step 5
Step 5: The zigzag scan is used to map the 8x8 matrix to a 1x64
vector. Zigzag scanning is used to group low-frequency
coefficients to the top level of the vector and the high coefficient
to the bottom. To remove the large number of zero in the
quantized matrix, the zigzag matrix is used.
More clearly Zig-zag Scan
JPEG Compression: Step 6
Step 6: Next step is vectoring, the different pulse code
modulation (DPCM) is applied to the DC component. DC
components are large and vary but they are usually close to the
previous value. DPCM encodes the difference between the
current block and the previous block..
JPEG Compression: Step 7
Step 7: In this step, Run Length Encoding (RLE) is applied to
AC components. This is done because AC components have a
lot of zeros in it. It encodes in pair of (skip, value) in which skip is
non zero value and value is the actual coded value of the non
zero components.
JPEG Compression: Step 8
Step 8: In this step, DC components are coded into Huffman.
JPEG Compression - 1

Input Image

(b) DCT for an 8´8 image block


JPEG Compression - 2

Luminance quantization table Chrominance quantization table

16 11 10 16 24 40 51 61 17 18 24 47 99 99 99 99
12 12 14 19 26 58 60 55 18 21 26 66 99 99 99 99
14 13 16 24 40 57 69 56 24 26 56 99 99 99 99 99
14 17 22 29 51 87 80 62 47 66 99 99 99 99 99 99
18 22 37 56 68 109 103 77 99 99 99 99 99 99 99 99
24 35 55 64 81 104 113 92 99 99 99 99 99 99 99 99
49 64 78 87 103 121 120 101 99 99 99 99 99 99 99 99
72 92 95 98 112 100 103 99 99 99 99 99 99 99 99 99
JPEG Compression - 3

Ø Quantization Result
JPEG Compression -4

v Restored DCT Image by multiplying the constants


in the Quantization Table.
JPEG Compression - 5

Restored Grayscale Value

Restored Image

Difference between original and restored


Block Artifacts
MPEG
• Motion Picture Experts Group
• Steps
– Temporal redundancy reduction
– Motion compensation
– Spatial redundancy reduction
– Entropy coding
– File is saved as .mp3 or mp4
Motion Compensation
• Assume the current picture can be locally
modeled as a translation of the pictures of
some previous time.
• Each picture is divided into blocks of 16
x 16 pixels, called a macroblock.
• Each macroblock is predicted from the
previous or future frame, by estimating
the amount of the motion in the
macroblock during the frame time interval.
Motion Compensation steps

https://www.youtube.com/watch?v=Ky4CaKw7tdo
Motion Compensation
• Data processing:
• It is required to apply motion prediction at
every macroblock level
• Here predictive coding is applicable only that
part of image where motion is present
• There are 3 types of predictions are available
1. forward prediction :
2. backward prediction
3. bidirectional prediction.
Temporal Redundancy
Reduction
• Three frames
– I frame (intra picture)
– P frame (predicted picture)
– B frame (bidirectionally interpolated
picture)
Motion Compensation
Motion Compensation: DCT
• DCT: requires to remove High frequency
components
• We have to apply DCT on 8*8 data blocks
Motion Compensation: Quantization

• Quantization: Apply this process on


frequency domain coefficient
• This plays an important role to store
minimum data in video
Motion Compensation: Coding
• Entropy encoding
Steps:
1. convert 2D symbols to Id
2. apply Zig-Zag pattern on coefficients
• Use RLE for 1D pattern
• Apply Huffman coding
Hardware Implementation
• High-speed hardware for JPEG and
MPEG compression and
decompression significantly reduces
the computational overhead
Chapter 8
Image Compression

Truncated Huffman code


• Block size = 12
• Huffman coding for 13 symbols.
The last element represents the
9 symbols between 13 and 21.
• Use 13th code(10) word as a
prefix

B2-Code
• Divide symbols into blocks with
the size of 4
• Represent the symbols in each
group with 2bits
• Concatenate them with
continuation bit C
• a11 can be presented either
001010 or 101110 depending on
the bit assigned to C
Binary Shift
• Divide into blocks of 7 symbols
• Generate prefix code with 7
symbols
Huffman shift
http://site.iugaza.edu.ps/jroumy/files/Tru • Generate Huffman code for the 8
symbols(7 symbols+ sum of all
ncated-huffman.pdf others)
https://www.youtube.com/watch?v=lvhe
u2ElJ-E

You might also like