forked from sigproc/cued_sf2_lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdct.py
More file actions
45 lines (36 loc) · 1 KB
/
dct.py
File metadata and controls
45 lines (36 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from cued_sf2_lab.dct import dct, idct, dctbpp, regroup
from cued_sf2_lab.familiarisation import (
load_mat_img,
plot_image,
optimise_stepsize,
rms_error,
plot_grid,
)
from cued_sf2_lab.laplacian_pyramid import quantise
import matplotlib.pyplot as plt
plt.style.use("graphs.mplstyle")
X_pre_zero_mean, cmaps_dict = load_mat_img(
img="lighthouse.mat", img_info="X", cmap_info={"map", "map2"}
)
X = X_pre_zero_mean - 128.0
N = 8
Y = dct(X, N)
Yr = regroup(Y, N)
Xq = quantise(X, 17)
target_rms = rms_error(X, Xq)
res = optimise_stepsize(lambda stepsize: idct(quantise(Y, stepsize), N), X, target_rms)
Yq = quantise(Y, res.x)
nbits = dctbpp(regroup(Yq, N), N)
Z = idct(Yq, N)
plot_grid(
[
(X, "Original image X"),
(Yr, "Regrouped DCT Yr"),
(Xq, f"Quantised Xq\n(Stepsize: {17}, RMS error: {target_rms:.2f})"),
(Z, f"DCT compressed Z\n(Stepsize: {res.x:.2f}, RMS error: {target_rms:.2f})"),
],
nrows=2,
ncols=2,
sharex=True,
sharey=True,
)