2. Blocking artifacts
• Picture coding/comprssion standards such as JPEG and MPEG
are based on block-based discrete cosine transform.
• Thus, a loss of quality might occur in an encoded image such
as blocking or ringing artifacts.
• Blocking artifacts or “MacroBlocking” are most visible on fast
moving images such as sports or action scenes.
3. Origin of blocking artifacts
Two components can be the source of blocking artifacts:
• The most significant source is the block-based Discrete Cosine
Transform (DCTs) in intra and inter frame prediction coding.
Coarse Quantization of the transform coefficients can cause
visually disturbing discontinuities at the block boundaries.
• The second source of blocking artifact is motion compensated
prediction.
Motion compensated blocks are generated by copying
interpolated pixel data from different locations of possibly
different reference frames.
In fact, in the copying process, existing edge discontinuties in
reference frames could be carried into the interior of the block to
be compensated. (Does this apply to mpeg-2?)
4. Blocking artifacts within the blocks
• Blocking artifacts will be propagated within the block as a
result of motion compensation.
• These artifacts will be more visible within the flat regions than
the complex detailed regions.
• This implies that smoothing the flat regions should cover the
inside of the block as well as the outside of the block.
• Practical aspects of implementing something to detect what
happen to the pixels within the block is difficult.
• H264 specs almost touches all luma pixels, as it filters two
pixels on each side of the 4x4 boundary.
• In MPEG-2, the block is 8x8 and it is not clear how to check
what happened within the block, as opposed to the edges.
5. Post-processing deblocking filter
• In post-processing approach: The deblocking filter operates
on the display buffer outside of the coding loop.
• In the post-processing approach, the frame is first decoded
into a reference frame buffer. The deblocking filter is then
applied on the decoded pixel values.
• An additional frame storage may be needed to store the
filtered frame to be passed to the display device.
• This is one of the reasons that H.264 and H.263+ have
proposed to use the deblocking filter within the coding loop.
Other reasons for including the deblocking filter within the
loop is the fact that performing motion compensation on the
filtered values produces better results.
6. MPEG-2 Quantization in the encoder
• When the DCT is computed for a block, the coefficients for
high spatial frequencies are represented with less precision.
This is done through Quantization.
• DCT coefficients are quantized by a non-zero positive integer
called the quantization value (quantization scale) and
rounding the quotient, i.e. the quantized DCT coefficient to the
nearest integer value.
• The bigger the quantization value is, the lower the precision of
the quantized DCT coefficients. This leads to more blocking
artifacts.
7. Description of the reconstruction filter in H263+
• H263+ = H.263 plus more options such as:
• Arbitrary frame size, pixel aspect ratio square), and picture
clock frequency
• Loop de-blocking filter
• The ITU-T H.263 video compression standard were developed
to implement video conferencing via LANs, DSL, ..etc. The
H.263 supports video resolutions of 1408x1152(16CIF),
704x576(4CIF),352x288(CIF),176x144(QCIF) and
128x96(SQCIF) at up to 29.97 frames per second.
8. Deblocking filter mode in H263+
• The H263+ introduces a deblocking filter inside the coding
loop.
• The filter is applied to the edge boundaries of 8x8 blocks to
reduce the blocking artifacts.
• The filter coefficients depends on the macroblock’s quantizer’s
step size, with larger coefficients used for a coarser quantizer.
9. Deblocking filter mode in H263+(is in the coding loop)
• Filter pixels along block boundaries while preserving edges in the image
content.
• Filter is in the coding loop which means it filters the decoded reference frame
used for motion compensation.
• Can be used in conjunction with a post-filter to further reduce coding artifacts.
11. Deblocking Filter mode in H263+
• A,B,C and D are replaced by new values, A1,B1,C1, and D1
based on a set of non-linear equations.
• The strength of the filter is proportional to the quantization
strength.
12. Deblocking filter mode in H263+
• A,B,C, D are replaced by A1,B1,C1,D1:
• B1 = clip(B+d1)
• C1=clip(C- d1)
• A1 = A – d2
• D1 = D + d2
• d2= clipd1((A-D)/4,d1/3)
• d1 = Filter((A-4B+4C-D)/8, strength(QUANT)
• Filter(x,strength) = sign(x) * * (MAX(0, abs(x) – MAX(0, 2*( abs(x) - Strength) ) ) )
The deblocking filter is in the “coding loop”
13. Post-filter in H263+
• Filter the decoded frames horizontally first, then vertically
using a 1-D filter
• The post-filter strength is proportional to the quantization:
strength(QUANT).
• D1 = D + Filter((A+B+C+E+F+G-6D)/8,Strength)
• This filter is supposed to work with the filter within the
loop. It is not clear that this filter by itself is enough.
14. JPEG deblocking algorithms
• The main issue with JPEG or still image deblocking
techniques, is the fact that they are developed for non real-
time processing.
• Due to this fact, they tend to be computationally very
expensive to implement.
16. Video Decoder
• The video decoder (VDCD) fetches video elementary stream
(ES) from external memory.It removes sequence, Group of
Pictures (GOP), picture and slice headers.
• Picture and user information are extracted and encoded MPEG
is decoded.
• The decoded video data is stored in external memory.
• The decoded data is stored to be fetched later by motion
compensation and display.
17. Video Decoder
• The video decoder is composed of:
– Variable Length Decoder (VLD)
– Dequantizer (DQNT)
– Inverse Discrete Cosine Transform (IDCT)
– Final Adder (FA)
– Video Controller (VC)
– Motion Compensator (MO)
18. Dequantizer
• The dequantizer module(DQNT) receives commands and data from the
Variable Length Decoder module (VLD) and generates non-zero
coefficients which are processed by the discrete Cosine Transform (IDCT)
module.
• DQNT module decodes and unzigs run/level coded data. DQNT module
stores quantizer scale factors and matrix values from bitstreams.
21. MPEG2 vs. H.264
• Both algorithms are based on a common heritage of DCT based, hybrid
image coding, first used in H.261 and MPEG1.
• Both algorithms can be represented by the same high-level block diagrams.
Both algorithms are image transform coded, forward/backward block
motion compensated prediction with entropy coded transform coefficients.
• However the algorithms differ significantly in the methods selected for
image transforms and entropy coding.
• H.264 achieves at least a 2X improvement over MPEG4. Thus H.264 is
likely to supplant MPEG2 and MPEG4 in new applications.
• Example: To achieve a PSNR(Peak Signal to RMS Noise Ratio ) level
of 28, NBA must be coded at a rate of 5 mbps using MPEG2, but only
1.8 mbps using H.264.
25. Description of the Reconstruction Filter in H264
• A filter is applied to every decoded macroblock in order to
reduce blocking distortion.
• There are three types (3, 4, 5 taps) of filters for both
• vertical and horizontal directions and the filter decision is
based on the combinations of conditions including boundary
strengths, image gradients and thresholds that are affected by
the average quantization parameters across the block
boundary.
26. Deblocking Loop Filter in H264: Boundary Strength
Block modes and conditions Boundary-
strength
One of the blocks(4x4 block) is an intra and the
edge is a macro-block edge(lies on 16x16
boundary).
4
One of the blocks is intra and the edge is not a
macro-block edge.
3
One of the blocks has coded residuals 2
Difference of block motion >= 1 luma sample
distance
1
Motion compensation from different reference
frames
1
else 0
Orderofconditionevaluation
27. Deblocking Loop Filter in H264: Boundary Strength
Block boundary
between block p and q
Block p or q
intra coded or
slice type is SI or SP
?
Bs=3
Block boundary
is also Macroblock
boundary
?
Coefficients
coded in block
p or q
?
Bs=2Bs=4
|V1(p,x) - V1(q,x)| >= 1 or
|V1
(p,y) - V1
(q,y)| >= 1 or
if bi-predictive
|V2(p,x) - V2(q,x)| >= 1 or
|V2(p,y) - V2(q,y)| >= 1
Bs=0
(skip)
Bs=1
YES NO
YES
YES
NO
NO
Block p and q have
different reference frames
or a different number of
reference frames?
YES
NO YES
NO
28. Boundary Strength
• To every edge between two 4x4 luminance sample blocks, a Boundary
strength Bs parameter is assigned an integer value form 0 to 4.
• The value of “Bs” depend on the modes and coding conditions of the two
adjacent blocks.
• Conditions are evaluated from top to bottom, until one of the conditions
holds true and the corresponding value is assigned to Bs.
• Bs determines the strength of the filtering performed on the edge, including
a selection between two filtering modes.
29. Deblocking Filtering Condition
• Filtering conditions: are used to decide whether or not to switch off the
filtering when there is enough change across the block boundary in the
original image to indicate a real edge and not some blocking artifact.
• The decision is based on threshold values: α and β
• As the blocking artifacts change with the value of the Quantization
parameter, The threshold values should adapt to the value of Qp (the
quantization parameter).
• It is expected that as “Qp” increases, the blocking artifacts contribution to
the change in pixel-value across the block boundary would also increase.
• Conversely, when “Qp” is small, blocking effects should not affect the
image boundary significantly, and as such, the thresholds are set very low.
• Any change, other than a small gradient at the boundary is more likely to
be an image feature than a blocking artifacts/
30. Alpha α -table
• IndexA = clip3(0,51,QPav + Filter_offset_A)
• The α-table is indexed by IndexA which is related to Qp as shown.
• Filtering is only performed for points that lie below the curve.
0 10 20 30 40 50 60
0
50
100
150
200
250
300
alpha index vs. QPav
QPav
alpha
Filtering
No-Filtering
31. Beta β -table
• IndexB = clip3(0,51,QPav + Filter_offset_B)
• The β -table is indexed by IndexB which is related to Qp as
shown above
0 10 20 30 40 50 60
0
2
4
6
8
10
12
14
16
18
beta vs. QP
av
QP
av
beta
Filtering
No Filtering
32. Value for filter clipping parameter C0 as a function of
IndexA and Bs (boundary strength)
0 10 20 30 40 50 60
0
5
10
15
20
25
C0 vs. QPav
QPav
C0
Bs=1
Bs=2
Bs=3
• C0 is used as a limiting value.
33. Boundaries of macr-blocks to be filtered, H.264
• 4x4 block boundary represent the boundaries to be filtered for luma in both vertical
and horizontal direction.
16x16 block boundary
(solid red line)
4x4 block boundary (solid blue line)
Horizontal edges
for chroma
filtering (green
dashed line)
Vertical edges for
chroma filtering
(green dashed
line)
35. Deblocking Filtering Condition: for Bs < 4
• iff
Bs ≠ 0 &&
|p0 – q0| < α &&
|p1 – p0| < β &&
|q1 – q0| < β is true
• The values of the thresholds α and β are dependent on the
average value of QP for the two blocks
p3 p2 p1 p0 q0 q1 q2 q3
36. H.264 : P0,Q0 filtering of edges with Bs < 4
• A 4-tap linear! filter, is applied with inputs p1, p0, q1,q0, producing filtered
output P0 and Q0
• C is determined by setting it equal to C0. The value of C could be
incremented by a “1” or “2” depending on the relations described above.
<∧<+
<+
≥∧≥
=
−=
−=
∆−=
∆+=
+−+−
−=∆
)()(20
)(10
)()(0
02
02
)0(10
)0(10
)
8
4)11()00(*4
,,(3
ββ
β
ββ
qp
p
qp
q
p
aaiffC
aiffC
aaiffC
C
qqa
ppa
qclipQ
pclipP
qppq
CCclip p3 p2 p1 p0 q0 q1 q2 q3
37. H.264 : P0,Q0 filtering of edges with Bs < 4
• The new pixel values P0,Q0 showing the contribution of the term 4(q0-p0)/8,
will align P0 and Q0
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
0)00( ≥− pqP0,Q0
38. H.264 : P0,Q0 filtering of edges with Bs < 4
• The new pixel values P0,Q0 showing the contribution of the term (p1-q1)/8,
will adjust the position of P0 and Q0 accordingly
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
0)11( ≤− qp
P0
Q0
Final edge
Final Q0
Final P0
39. H.264 : P1,Q1 filtering of edges with Bs < 4
• Moreover, if |p2-p0| is less than a threshold, then a 4-tap linear! filter is applied on
the points p2,p1,p0,q0. This is used to compute the new value of P1. Similarly for Q1.
• The filter for p1 does in fact assume that the two pixels around p1 are represented by
p2, and (p0+q0)/2 which is the average value of p0 and q0.
• The difference between p1 and the two surrounding pixels dscribed above is
computed. The average value of these two differences is computed, and added to the
original value of p1 to compute the new value of P1.
• Similar argument apply to Q1 computation
02
02
:
)02()
2
1*22/)00(2
,0,0(311
)02()
2
1*22/)00(2
,0,0(311
qqa
ppa
where
qqaiff
qpqq
CCclipqQ
ppaiff
ppqp
CCclippP
q
p
q
p
−=
−=
<−=
−++
−+=
<−=
−++
−+=
β
β p3 p2 p1 p0 q0 q1 q2 q3
p3 p2 p1 p0 q0 q1 q2 q3
40. H.264 : P1 filtering of edges with Bs < 4
• The average value of (p2-p1) and ((p0+q0)/2-p1) is added to p1 to form the new
value P1
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
)
2
00
(
qp +
P0
Q0
0)12( ≥− pp
0)1)
2
00
(( ≥−
+
p
qp
41. H.264 : P1 filtering of edges with Bs < 4
• So, if (p2-p0) is below some threshold β, which indicates the image does
not have a lot of details, then filtering is done on p1, and the resulting pixel
P1 is shown as indicated. Otherwise, p1 retain its original value.
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
)
2
00
(
qp +
P0
Q0
P1
Final P1
42. H.264 : Q1 filtering of edges with Bs < 4
• The average value of (q2-q1) and ((p0+q0)/2-q1) is added to q1 to
form the new value Q1
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
)
2
00
(
qp +
P0
Q0
0)1)
2
00
(( ≤−
+
q
qp
P1
0)12( ≥− qq
43. H.264 : Q1 filtering of edges with Bs < 4
• The average value of (q2-q1) and ((p0+q0)/2-q1) is added to q1 to
form the new value Q1
p3 p2 p1 p0 q0 q1 q2 q3
Block Boundary
p2 p1 p0 q1 q2q0
Decoded pixel positions
q3p3
p0
q0
)
2
00
(
qp +
P0
Q0
P1 Final Q1
Q1
44. H.264 : P0,P1,P2 Strong filtering of edges with Bs = 4
• Strong filtering is performed when the following
conditions hold:
• Bs = 4 &&
iff
(ap=|p2 – p0|) < β &&
|p0– q0| < (α/4 + 2) is true Apply strong filtering to
P0,P1,P2 as described next
Else only filter P0 as follows:
p3 p2 p1 p0 q0 q1 q2 q3
4
2101*2
0
+++
=
qpp
P
45. H.264 : Q0,Q1,Q2 Strong filtering of edges with Bs = 4
• Strong filtering is performed when the following
conditions hold:
• Bs = 4 &&
iff
(aq=|q2 – q0|) < β &&
|p0– q0| < (α/4 + 2) is true Apply strong filtering to
Q0,Q1,Q2 as described next
Else only filter Q0 as follows:
p3 p2 p1 p0 q0 q1 q2 q3
4
2101*2
0
+++
=
pqq
Q
46. αs= (α/4 + 2) is significantly less than α. This indicates that the application
of the strong filtering(Bs=4) will be more limited than the moderate filter
case (0<Bs<4)
p3 p2 p1 p0 q0 q1 q2 q3
0 10 20 30 40 50 60
0
50
100
150
200
250
300
alpha and alphas
vs. QPav
QPav
alpha alpha
alphas
H.264 : αs for Strong filtering of edges with Bs = 4
47. H.264 : P0,P1,P2 filtering of edges with Bs =4
• A 5-tap linear! filter, is applied, with inputs p2,p1, p0,q0,q1
producing filtered output P0.
• A 4-tap linear! filter, is applied, with inputs p2,p1,p0,q0
producing filtered output P1.
• In the case of luma filtering, p2 is also filtered, with inputs
p3,p2,p1,p0,q0 producing filtered output P2
8
40012*33*2
2
4
20012
1
8
410*20*21*22
0
+++++
=
++++
=
+++++
=
qpppp
P
filteringlumaiff
qppp
P
qqppp
P
p3 p2 p1 p0 q0 q1 q2 q3
p3 p2 p1 p0 q0 q1 q2 q3
p3 p2 p1 p0 q0 q1 q2 q3
48. H.264 : Q0,Q1,Q2 filtering of edges with Bs = 4
• A 5-tap linear! filter, is applied, with inputs q2,q1, q0,p0,p1
producing filtered output Q0.
• A 4-tap linear! filter, is applied, with inputs q2,q1,q0,p0
producing filtered output Q1.
• In the case of luma filtering, q2 is also filtered, with inputs
q3,q2,q1,q0,p0 producing filtered output Q2
8
40012*33*2
2
4
20012
1
8
410*20*21*22
0
+++++
=
++++
=
+++++
=
pqqqq
Q
filteringlumaiff
pqqq
Q
ppqqq
Q
p3 p2 p1 p0 q0 q1 q2 q3
p3 p2 p1 p0 q0 q1 q2 q3
p3 p2 p1 p0 q0 q1 q2 q3
49. A post-processing deblocking filter for MPEG2/4
A B C E FD
Decoded pixel positions
Block Boundary
X=|D-C|
PixelValue
50. A post-processing deblocking filter,(moderate Filtering)
8x8 block boundary
C
B
E
D
p0
p1
q1
q0
q2
CB D E p1 p0 q0 q1 q2p2
p2 A
F
FA
If |C-D|<1.25*Quant_scale
{
x = D-C
A’ = A
B’ = B + x/8
C’ = C + x/2
D’ = D – x/2
E’ = E - x/8
F’ = F
}
51. A post-processing deblocking filter,(moderate Filtering)PixelValue
A B C E FD
Decoded pixel positions
Block Boundary
x=|D-C|
X/2
X/8
A’
B’
C’,D’
E’
F’
52. A post-processing deblocking filter,(moderate Filtering)
• The proposed moderate filter, changes only 4 pixels at the block boundary.
• The advantage of using such a moderate filter, is the fact that it does not
blur the regions with high spatial details.
• The filtering effect is restricted to regions with strong blocking effects,
specially those locacted near the edge of the block.
53. A post-processing deblocking filter,(Strong Filtering)
C
B
E
D
p0
p1
q1
q0
q2
CB D E p1 p0 q0 q1 q2p2
p2
8x8 block boundary
A
F
FA
If |C-D|<2*Quant_scale
{
x = D-C
A’ = A + x/8
B’ = B + x/4
C’ = C + x/2
D’ = D – x/2
E’ = E – x/4
F’ = F – x/8
}
54. A post-processing deblocking filter,(Strong Filtering)
A B C E FD
Decoded pixel positions
Block Boundary
X=|D-C|
PixelValue
X/2 X/4
X/8
55. A post-processing deblocking filter,(Adaptive Filtering)
• The moderate filter, changes only 4 pixels at the block boundary.
• The strong filter, changes 6 pixels at the block boundary.
• The strength of the filter is to be chosen adaptively according to the
blocking effect.
• … Next time, we will describe how to adaptively determine between the
strong and moderate filtering.
• Start using an mpeg-2 encoder and use it under different quantization
scales/parameters, see how the different filtering algorithms behave.
60. Computing the Power Signal to Noise Ratio
• MSE = Mean squared Error
• PSNR = Power Signal to Noise Ratio
2
1 1
]),(ˆ),([
1
∑∑= =
−⋅
⋅
=
x yN
i
N
jyy
jifjif
NN
MSE
2
1 1
]),(ˆ),([
1
∑∑= =
−⋅
⋅
=
x yN
i
N
jyy
jifjif
NN
RMSE
)
255
log(20
RMSE
PSNR ⋅=
61. Deblocking an arbitrary scaled Frame: Horizontal
Direction
• Create a histogram that takes into account that scaling might have been
implemented on the frame in the horizontal direction.
64. Detecting vertical block boundary
• Detecting the vertical block boundary
• H is the number of pixel in the horizontal direction (no of pixels per line)
• V is the number of lines (number of lines per frame)
∑
∑
∑
=
−−
=
=
−=
−=
−=
V
i
HiHiH
V
i
ii
V
i
ii
PPBV
PPBV
PPBV
1
1,,)1(
1
3,2,)2(
1
2,1,)1(
...
66. Detecting a horizontal block boundary
• Detecting the horizontal block boundary
• H is the number of pixel in the horizontal direction (no of pixels per line)
• V is the number of lines (number of lines per frame)
∑
∑
∑
=
−−
=
=
−=
−=
−=
H
j
jVjVV
H
j
jj
H
j
jj
PPBH
PPBH
PPBH
1
,1,)1(
1
,2,3)2(
1
,1,2)1(
...