-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinter_predict.m
63 lines (63 loc) · 2.7 KB
/
inter_predict.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
53
54
55
56
57
58
59
60
61
62
63
function dst = inter_predict(img,EOB,qScale)
im_y = img(:,:,1);
im_cb = resampling(img(:,:,2),[1,2]);
im_cr = img(:,:,3);
im_cr = resampling(im_cr,[1,2]);
para_y = [7/8,-1/2,5/8];
para_cb = [3/8,-1/4,7/8];
para_cr = para_cb;
image_y_res = cal_pre(im_y,para_y);
image_cb_res = cal_pre(im_cb,para_cb);
image_cr_res = cal_pre(im_cr,para_cr);
im_dct_y = blockproc(image_y_res,[8,8],@(block_struct) DCT8x8(block_struct.data));
im_dct_cb = blockproc(image_cb_res,[8,8],@(block_struct) DCT8x8(block_struct.data));
im_dct_cr = blockproc(image_cr_res,[8,8],@(block_struct) DCT8x8(block_struct.data));
im_quant_y = blockproc(im_dct_y,[8,8],@(block_struct) Quant8x8(block_struct.data,qScale,"luminance"));
im_quant_cb = blockproc(im_dct_cb,[8,8],@(block_struct) Quant8x8(block_struct.data,qScale,"chroma"));
im_quant_cr = blockproc(im_dct_cr,[8,8],@(block_struct) Quant8x8(block_struct.data,qScale,"chroma"));
im_zigz_y = blockproc(im_quant_y,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
im_zigz_cb = blockproc(im_quant_cb,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
im_zigz_cr = blockproc(im_quant_cr,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
%im_zigz_y = blockproc(image_y_res,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
%im_zigz_cb = blockproc(image_cb_res,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
%im_zigz_cr = blockproc(image_cr_res,[8,8],@(block_struct) ZigZag8x8(block_struct.data));
im_zigz_y = im_zigz_y(:);
im_zigz_cb = im_zigz_cb(:);
im_zigz_cr = im_zigz_cr(:);
im_zig_z = [im_zigz_y;im_zigz_cb;im_zigz_cr];
dst = ZeroRunEnc_EoB(im_zig_z,EOB);
%res = [image_y_res(:);image_cb_res(:);image_cr_res(:)];
%res = res';
%min_res = min(res);
end
function res = cal_pre(mat,para)
[len,col] = size(mat);
image_n = zeros(len,col);
rec_im = zeros(len,col);
error = zeros(len,col);
image_n(1,:) = round(mat(1,:));
image_n(:,1) = round(mat(:,1));
rec_im(:,1) = round(mat(:,1));
rec_im(1,:) = round(mat(1,:));
% image_n(1,:) = mat(1,:);
% image_n(:,1) = mat(:,1);
% rec_im(:,1) = mat(:,1);
% rec_im(1,:) = mat(1,:);
a1 = para(1);
a2 = para(2);
a3 = para(3);
for j =2:len
for k = 2:col
image_n(j,k) = a1*rec_im(j,k-1)+a2*rec_im(j-1,k-1)+a3*rec_im(j-1,k);
error(j,k) = round(mat(j,k)-image_n(j,k));
% error(j,k) = mat(j,k)-image_n(j,k);
rec_im(j,k) = image_n(j,k)+error(j,k);
end
end
%res = rec_im-image_n;
res = error;
res(1,:) = round( mat(1,:));
res(:,1) = round(mat(:,1));
% res(1,:) = mat(1,:);
% res(:,1) = mat(:,1);
end