Professional Documents
Culture Documents
10 DCT PDF
10 DCT PDF
Transform
f(i) = F1 (u)
2 X
12 N1 h u i
= (u)cos (2i + 1) F(u),
N u=0
2N
where
1 for = 0,
() = 2
1 otherwise.
CM3106 Chapter 10: DCT 1D DCT 10
DCT Example
Lets consider a DC signal that is a constant 100,
i.e f(i) = 100 for i = 0 . . . 7 (see DCT1Deg.m):
So the domain is [0, 7] for both i and u
We therefore have N = 8 samples and will need to work
8 values for u = 0 . . . 7.
We can now see how we work out F(u):
As u varies we work can work for each u a component or
a basis. F(u).
Within each F(u), we cam work out the value for each
Fi (u) to define a basis function
Basis function can be pre-computed and simply looked up
in DCT computation.
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:
Note: (0) = 1 and cos(0) = 1
2
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
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
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.
CM3106 Chapter 10: DCT 1D DCT 18
DCT Matlab Example
D1 = bases*f;
figure % plot D1
stem(D1);
2 2 2 2 X X
1 1 N1 M1
F(u, v) = (u)(v)
N M
i=0 j=0
h u i h v i
cos (2i + 1) cos (2j + 1) f(i, j)
2N 2M
and the corresponding inverse 2D DCT transform is simply
F1 (u, v), i.e.:
f(i, j) = F1 (u, v)
12 12 N1
2 2 X M1
X
= (u)(v)
N M
u=0 v=0
h u i h v i
cos (2i + 1) cos (2j + 1) F(u, v) .
2N 2M
CM3106 Chapter 10: DCT 2D DCT 20
Applying The DCT
1X h v i
G(i, v) = (v)cos (2j + 1) f(i, j)
2 i 16
1X h u i
F(u, v) = (u)cos (2i + 1) G(i, v)
2 i 16
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.
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);