-
Notifications
You must be signed in to change notification settings - Fork 0
/
SingleCom.m
52 lines (48 loc) · 1.42 KB
/
SingleCom.m
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
46
47
48
49
50
51
52
function comp_image = Compress(orig_image)
RGB=orig_image;
%下面是对 RGB 三个分量进行分离
R=RGB(:,:,1);
G=RGB(:,:,2);
B=RGB(:,:,3);
%RGB->YUV
Y=0.299*double(R)+0.587*double(G)+0.114*double(B);
[xm, xn] = size(Y);
U=-0.169*double(R)-0.3316*double(G)+0.5*double(B);
V=0.5*double(R)-0.4186*double(G)-0.0813*double(B);
T=dctmtx(8);
%进行 DCT 变换 BY BU BV 是 double 类型
BY=blkproc(Y,[8 8],'P1*x*P2',T,T');
BU=blkproc(U,[8 8],'P1*x*P2',T,T');
BV=blkproc(V,[8 8],'P1*x*P2',T,T');
%低频分量量化表(细量化表)
a=[
16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 55;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99;
];
%高频分量量化表(粗量化表)
b=[17 18 24 47 99 99 99 99;
18 21 26 66 99 99 99 99;
24 26 56 99 99 99 99 99;
47 66 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;];
%使用量化表对三个分量进行量化,Y采用细量化表,U采用粗量化表
BY2=blkproc(BY,[8 8],'round(x./P1)',a);
BU2=blkproc(BU,[8 8],'round(x./P1)',b);
BV2=blkproc(BV,[8 8],'round(x./P1)',b);
% 调用图像压缩函数
comp_image_Y=img2jpg(BY2,1);
comp_image_U=img2jpg(BU2,2);
comp_image_V=img2jpg(BV2,3);
% 将图像存储为一维矩阵
comp_Y_U = cat(1, comp_image_Y, comp_image_U);
save_image = cat(1, comp_Y_U, comp_image_V);
comp_image = save_image;