3.2. Image Compression (Part 1)
3.2. Image Compression (Part 1)
ិ ជី ថ
ី លកម្ពុជា
Cambodia Academy of Digital and Technology
4
2- Resampling Technique
• Resampling is the mathematical technique used to create a new
version of the image with a different width and/or height in pixels.
• Increasing the size of an image is called up-sampling; reducing its
size is called down-sampling.
• Techniques for resampling:
Nearest neighbor interpolation
Linear interpolation
Cubic interpolation
Bilinear interpolation
Bicubic interpolation, etc
5
2- Resampling Technique
6
2.1- Nearest Neighbor Technique
• Assign the value of the nearest neighbor to the value of the new
point.
7
2.1- Nearest Neighbor Technique
• Ex: Supposed we have a 3x3 image and we want to enlarge it to a
6x6 image
1 2 3
1 2 3
6 5 4
6 5 4
7 0 3
7 0 3
8
2.2- Linear Interpolation
• Weighting the values of the 2 neighboring points to the value of
the new point.
9
2.2- Linear Interpolation
• Linear equation:
𝑦 − 𝑦0 𝑦1 − 𝑦0
=
𝑥 − 𝑥0 𝑥1 − 𝑥0
• We get solution:
𝑦1 − 𝑦0
𝑦 = 𝑦0 + (𝑥 − 𝑥0 )
𝑥1 − 𝑥0
Or
𝑥1 − 𝑥 𝑥 − 𝑥0
𝑦= 𝑦0 + 𝑦1
𝑥1 − 𝑥0 𝑥1 − 𝑥0 10
2.3- Bilinear Interpolation
• Bilinear interpolation is an extension of linear interpolation for
interpolating functions of two variables on a rectilinear 2D grid.
• Suppose that we want to find the value of
unknown function f at the point (x, y). And
we know the value of f at Q11 = (x1, y1), Q12 =
(x1, y2), Q21 = (x2, y1), and Q22 = (x2, y2).
1. We first do linear interpolation in the x-direction:
𝑥2 − 𝑥 𝑥 − 𝑥1
𝑓(𝑥, 𝑦1 ) = 𝑓(𝑄11 ) + 𝑓(𝑄21 )
𝑥2 − 𝑥1 𝑥2 − 𝑥1
𝑥2 − 𝑥 𝑥 − 𝑥1
𝑓(𝑥, 𝑦2 ) = 𝑓(𝑄12 ) + 𝑓(𝑄22 )
𝑥2 − 𝑥1 𝑥2 − 𝑥1 11
2.3- Bilinear Interpolation
2. We proceed by interpolating in the y-direction to obtain:
𝑦2 − 𝑦 𝑦 − 𝑦1
𝑓(𝑥, 𝑦) = 𝑓(𝑥, 𝑦1 ) + 𝑓(𝑥, 𝑦2 )
𝑦2 − 𝑦1 𝑦2 − 𝑦1
𝑦2 − 𝑦 𝑥2 − 𝑥 𝑥 − 𝑥1 𝑦 − 𝑦1 𝑥2 − 𝑥 𝑥 − 𝑥1
= ( 𝑓(𝑄11 ) + 𝑓(𝑄21 )) + ( 𝑓(𝑄12 ) + 𝑓(𝑄22 )
𝑦2 − 𝑦1 𝑥2 − 𝑥1 𝑥2 − 𝑥1 𝑦2 − 𝑦1 𝑥2 − 𝑥1 𝑥2 − 𝑥1
1
= (𝑓(𝑄11 )(𝑥2 − 𝑥)(𝑦2 − 𝑦) + 𝑓(𝑄21 )(𝑥 − 𝑥1 )(𝑦2 − 𝑦))
(𝑥2 − 𝑥1 )(𝑦2 −𝑦1 )
+ (𝑓(𝑄12 )(𝑥2 − 𝑥)(𝑦 − 𝑦1 ) + 𝑓(𝑄22 )(𝑥 − 𝑥1 )(𝑦 − 𝑦1 ))
1 𝑓(𝑄11 ) 𝑓(𝑄12 ) 𝑦2 − 𝑦
𝑓(𝑥, 𝑦) = 𝑥2 − 𝑥 𝑥 − 𝑥1
(𝑥2 − 𝑥1 )(𝑦2 −𝑦1 ) 𝑓(𝑄21 ) 𝑓(𝑄22 ) 𝑦 − 𝑦1
12
2.3- Bilinear Interpolation
• Ex: Use bilinear interpolation, to get pixel
value of another point as shown figure.
• First linearly interpolating between the
values at column 14 and 15 on each rows 20
and 21, giving
1 2
6 5
14
2.4- Cubic Interpolation
• Using the values of the 4 neighboring points to form a cubic
function 𝑓 𝑥 = 𝑎𝑥 3 + 𝑏𝑥 2 + 𝑐𝑥 + 𝑑
Form 4 equations using f (x1), f (x2), f (x3), and f (x4)
Solve for the 4 coefficients {a,b,c,d}
Find f (x‘ )
15
2.5- Matlab Implementation
• Group work of Matlab on:
Resize image using Matlab function.
Create own function for resolution reduction using average of
block 4x4.
Use own function for image implementation, etc.
16
3- Introduction to Image Compression
• Image compression can be
lossless or lossy, although most
existing image compression
systems are lossy.
• The fundamental tasks in image
compression are to reduce the
irrelevancy and correlation in
the images.
18
4- Lossy Image Compression
21
4.1- Scalar Quantization
• Example: Given a sequence of the
real numbers from some sampling
(1.1, 2, 3.3, 6.78, 5.48, 4, 3.333,
2.2, 2, 3, 2.1) and predefined
integers within a range of [0 10].
So these sampled real
numbers can easily be
rounded to (1, 2, 3, 7, 5, 4, 3,
2, 2, 2).
22
4.1- Scalar Quantization
Quantization is one of the simplest and most general ideas in
lossy compression.
Quantization is the process in which a large range of values is
represented by a much smaller set of values.
The function used to map the input sequence of values to the
output values is called quantizer.
If the values we are looking at are scalars, the process is called
scalar quantization.
23
4.1- Scalar Quantization
• There are two types of scalar quantizers:
midrise quantizer which does not have a zero output level.
midtread quantizer where zero is one of the output values.
24
4.1.1- Uniform Quantizers
• A scalar quantizer can be divided into:
uniform quantizer
non-uniform quantizer.
• Uniform quantizers are those for which the same size of an
increment (called step size).
• If ki and ki-1 are two adjacent range values on the x axis, The
reconstructed values are usually the midpoint of the two
adjacent step values (ki - ki-1)/2 and (q(ki)- q(ki-1))/2 (Figure (b)).
25
4.1.1.1- Uniform Quantizers
• This indicates that distortion caused by the quantizer.
• The most common distortion measure is the mean squared error
distortion.
26
4.1.1- Uniform Quantizers
• The difference between quantized and unquantized values is
called quantization error, or round off error.
27
4.1.2- Non-uniform Quantizers
• Non-uniform quantizers use variable step sizes. It applies different
step sizes to different amplitudes of an input signal.
• Two common functional types are used in non-uniform quantisers:
power-law and logarithmic.
29