Lecture 11: Discrete Cosine Transform
Lecture 11: Discrete Cosine Transform
11 : Discrete
Cosine Transform
Moving into the Frequency Domain
Frequency domains can be obtained through the
transformation from one (time or spatial) domain to the
other (frequency) via
Fourier Transform (FT) (see Lecture 3) —
MPEG Audio.
Discrete Cosine Transform (DCT) (new ) — Heart of
JPEG and
MPEG Video, MPEG Audio.
where
{ }
1
for ξ=0
Λ (ξ)= √2
1 otherwise
Plots of f(I) and F(U)
100
300
90
250
80
70
200
60
50 150
40
100
30
20
50
10
0 0
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
So for u = 0:
1
Note: Λ(0) = 2 √2
and cos(0) = 1
So F(0) is computed as:
1
F(0) = (1·100 + 1·100 + 1×100 + 1·100 + 1·100
2 √2
+ 1·100 + 1·100 + 1·100)
≈ 283
1
Here the values Fi(0) = (i = 0. .. 7).
2 √2
These are bases of Fi(0)
F(0) Basis Function Plot
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
1 2 3 4 5 6 7 8
0.4
0.3
0.2
0.1
−0.1
−0.2
−0.3
−0.4
−0.5
1 2 3 4 5 6 7 8
DCT1Deg.m explained:
i = 1:8% dimension of vector
f(i) = 100 % set function
figure(1) % plotf
stem(f);
%compute DCT
D =dct(f);
figure(2) % plotD
stem(D);
17
DCT Matlab Example
% Illustrate DCT bases compute DCT bases
% with dctmtx
bases =dctmtx(8);
% Plot bases:each row(j) of bases is the jth
%DCT Basis Function
for j= 1:8
figure %increment figure
stem(bases(j,:)); %plot rows
end
MATLAB dctmtx function computes DCT basis
functions.
Each row j of bases is the basis function F(j).
Plot each row.
18
DCT Matlab Example
D1 =bases*f’;
figure(1) % plot D1
stem(D1);
f (i , j) = F −1 ( u , v )
N −1 M −1
2 12 2 12
= ( )( )
N
⋅ ∑ ∑ Λ (u)⋅Λ( v )×
M i=0 j =0
πu πv
cos ( 2i+1)cos ( 2j+1)⋅F (u , v )
2N 2M
Applying The DCT
1 πv
G (i , v )= ∑
2 j
Λ (v )⋅cos
16
( 2j+1)⋅ f (i , j)
1 πv
F (u , v)= ∑ Λ ( u)⋅cos ( 2i+1)⋅G(i , v)
2 i 16
{ }
1
for ξ=0
Λ (ξ)= √2
1 otherwise
A =dctmtx(8);
A =A’;
Offset =5;
basisim =ones(N*(N+offset))*0.5;
B=zeros(N,N,N,N);
for i=1:N
for j=1:N
B(:,:,i,j)=A(:,i)*A(:,j)’;
%max(max(B(:,:,i,j)))-min(min(B(:,:,i,j)))
end;
end;
B = computation of 64 2D bases.
Create a 4D array: first two dimensions store a 2D image
for each i,j.
3rd and 4th dimension i and j store the 64 basis
functions.
DCT Basis Functions
for i=1:N
for j=1:N
minb = min(min(B(:,:,i,j)));
maxb = max(max(B(:,:,i,j)));
rangeb =maxb -minb;
if rangeb ==0
minb =0;
rangeb =maxb;
end;
figure(1)
imshow(basisim)
figure(2)
dispbasisim = imresize(basisim,4,’bilinear’);
imshow(dispbasisim);