-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLR_JNQD.m
155 lines (129 loc) · 5.27 KB
/
LR_JNQD.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
%% Learning-based just-noticeable-quantization-distortion modeling for perceptual video coding
% TIP 2018
% Sehwan Ki
% shki@kaist.ac.kr
%% Linear Regression based JNQD test code
clear;clc;close all;
load('spatial_freq.mat'); % spatial frequency with viewing distance = 1.3m
load('gradient_offset_weight_qp_intra.mat'); % Trained gradient and slope values
sequence = {'BQMall'};
QP = [22,27,32,37];
frame = [600];
H = [480];
W = [832];
for seq = 1:1
fprintf('seq : %s \n', strjoin(sequence(seq)));
height = H(seq);
width = W(seq);
N = 8; % dct block size
col = round(width/N);
row = round(height/N);
for fn = 1:frame(seq)
fprintf('Frame : %d \n', fn);
% 1. Input sequence
str = sprintf('test_sequences/%s_%dx%d_%d.yuv', strjoin(sequence(seq)), W(seq), H(seq), floor(frame(seq)/10));
[Y,U,V] = yuv_load(str, W(seq), H(seq), fn);
Y_ori = double(Y);
% 2. Calculate ERJND
C_ori = blkproc(Y_ori,[8 8],'dct2'); % original block DCT Coefficient
for r = 1:row
for c = 1:col
Y_ori_patch = Y_ori(N*(r-1)+1:N*r,N*(c-1)+1:N*c);
C_ori_patch = C_ori(N*(r-1)+1:N*r,N*(c-1)+1:N*c);
% ERJND_ori
ERJND_ori(N*(r-1)+1:N*r,N*(c-1)+1:N*c) = block_ERJND(Y_ori_patch,w,C_ori_patch);
end
end
%% 3-1. Gradient & Offset ¸¦ regression
% feature extraction
feat = All_test_feature(Y_ori);
feature = [];
for i = 1:5 % Using top-correlated 5 features
Temp = feat(:,:,i);
feature(i,:) = Temp(:);
end
feature(2,:) = log(feature(2,:)+eps);
feature(5,:) = log(feature(5,:)+eps);
feature(6,:) = ones(1,length(feature(1,:)));
for qp = 1:4
% 3-2. Linear regression for gradient & offset
% gradient & offset regression
if(qp == 1)
regress_gradient = (feature')*weight22_gradient;
regress_offset = (feature')*weight22_offset;
elseif(qp == 2)
regress_gradient = (feature')*weight27_gradient;
regress_offset = (feature')*weight27_offset;
elseif(qp == 3)
regress_gradient = (feature')*weight32_gradient;
regress_offset = (feature')*weight32_offset;
elseif(qp == 4)
regress_gradient = (feature')*weight37_gradient;
regress_offset = (feature')*weight37_offset;
end
%4. Determine an optimal alpha
alpha = [];
for i = 1:length(regress_gradient(:))
if(regress_gradient(i) == 0)
if(regress_offset(i) > 1)
alpha(i) = 0;
else
alpha(i) = 1;
end
else
% Assume that CDVM is linear function
val = (1 - regress_offset(i))/regress_gradient(i);
if(val < 0)
alpha(i) = 0;
elseif(val > 1)
alpha(i) = 1;
else
alpha(i) = val;
end
end
end
alpha = reshape(alpha,[row,col]);
% 5. Calculate LR-JNQD
for r = 1:row
for c = 1:col
alpha_image(N*(r-1)+1:N*r,N*(c-1)+1:N*c) = alpha(r,c);
end
end
alpha_image(find(isnan(alpha_image)==1)) = 0; % Remove nan values
LR_JNQD_val = alpha_image.*ERJND_ori;
% 6. Preprocessing using LR-JNQD
C_pre = sign(C_ori).*max(abs(C_ori)-LR_JNQD_val,0);
Y_pre = blkproc(C_pre,[8 8],'idct2');
Y_pre = uint8(Y_pre);
if(qp == 1)
alpha_qp22_I = alpha;
elseif(qp == 2)
alpha_qp27_I = alpha;
elseif(qp == 3)
alpha_qp32_I = alpha;
elseif(qp == 4)
alpha_qp37_I = alpha;
end
if(qp == 1)
% QP 22
filename = sprintf('%s/%s_QP22_LR_JNQD_all.yuv',strjoin(sequence(seq)),strjoin(sequence(seq)));
elseif(qp == 2)
% QP 27
filename = sprintf('%s/%s_QP27_LR_JNQD_all.yuv',strjoin(sequence(seq)),strjoin(sequence(seq)));
elseif(qp == 3)
% QP 32
filename = sprintf('%s/%s_QP32_LR_JNQD_all.yuv',strjoin(sequence(seq)),strjoin(sequence(seq)));
elseif(qp == 4)
% QP 37
filename = sprintf('%s/%s_QP37_QP_adapted_JNQD_all.yuv',strjoin(sequence(seq)),strjoin(sequence(seq)));
end
if(fn == 1)
mode = 1;
yuv_save(filename, Y_pre,U,V, mode);
else
mode = 2;
yuv_save(filename, Y_pre,U,V, mode);
end
end
end
end