Using DCT.mws for 2D-DCT Computation Demo
Short demo on ZigZag sequence and JPEG compression ratio
The dct.mws Maple Work Sheet
in http://cs.uccs.edu/~cs525/dct/dct.mws
implements a demonstation of 2D-DCT transformation. You can click the link and download it to PCs in the
PClab EN136, which are installed with Maple 10 Mathematics package, and then follow
the following instruction for computing the transformed coefficients. It will prompt the message indicating the dct.mws was created with maple 5 and ask for converting in maple 10 language. Accept that upgrade suggestion. You may have to hit enter on each statement to execute them.
-
hit enter on each of the functions
already created for dct until you hit the end of the file.
-
matrix f and F corresponds to
the input 8x8 image data and those of the transformed coefficients.
They are declared as
f:=array(1..8,
1..8);
F:=array(1..8,
1..8);
-
Note that matrix in Maple is
a special array with 1-based index.
f1:=array(0..7,
0..7);
F1:=array(0..7,
0..7);
f1 and F1 will not consider
as "matrices" and we can plot it with matrixplot() function.
-
To set the matrix f with all
elements = 0.125, we can implement the following procedure:
setf:=proc(f)
local
i, j;
for
i from 1 to 8 do
for
j from 1 to 8 do
f[i,j]:=0.125;
od;
od;
end;
then
call the fuction as
setf(f);
-
Note the language has a strong
PASCAL-like syntax.
-
set the values of the matrix
f by writing a simple procedure for creating the input 8x8 data.
-
finally enter getdctf(F); print(F);
matrixplot(F, axes=BOXED);
for printing the DCT coefficient
matrix F and 3D plots.
-
The following procedure, bwstrip
produces a matrix f with the black and whitel stripe pattern:
bwstrip:=proc(f)
local
i,j;
for
i from 1 to 8 do
for
j from 1 to 8 do
if (i mod 4 > 1) then f[i,j]:=0;
else f[i,j]:=100;
fi;
od;
od;
end;
bwstrip(f);
-
print(f) shows the matrix content
-
matrixplot(f, axes=BOXED) display
the pattern in 3D.
-
We then execute getdctf(F);
to obtain the 2D-DCT coefficients in F matrix.
-
Use print(F); to print the matrix
-
matrixplot(F, axes=BOXED)
to plot result in 3D.
-
Here is the zig-zag sequence
for the DCT coefficients in the matrix F:
400.0, 9 zeros, 400.0, EOB
-
Intermediate sequence for the
above zig-zag sequence (values encoded using the VLI encoding):
(9,400) (9, (9, 400)) (0, 0)
-
Here is the VLI encodign rule :
Note that value 400 in the group of values (-511..-256, 256..511) it will be encoded as (9, 400).
- Assume that the size and run
lenght fields are encoded with 4 bits, and the amplitude fields are encoded
using VLI encoding. We encode the intermediate sequence with 4+9+4+4+4+4+4=33
bits.
Assume each of original
source 8x8 block data is 8 bit, the compression ratio is 8*64:33=15.5:1