-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcomputeVIIDEOscore.m
179 lines (123 loc) · 6.13 KB
/
computeVIIDEOscore.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function VIIDEOscoreval = computeVIIDEOscore(vidname,height,width, ...
framenumber,blocksizerow,blocksizecol,...
blockrowoverlap,blockcoloverlap,filtlength)
%--------------------------------------------------------------------------
% Feature Computation
framevector = 1:2:framenumber-1;
count = 1;
for frameitr = framevector
[ydis1 ydis2] = readframe(vidname,frameitr,height,width);
[feat] = computeVIIDEOfeaturevector(ydis1,ydis2,...
blocksizerow,blocksizecol,blockrowoverlap, ...
blockcoloverlap,filtlength);
param(count).featvect = feat;
count = count +1;
end
% Score Computation
VIIDEOscorevect = computeVIIDEOscorevector(param);
VIIDEOscoreval = computefinalscore(VIIDEOscorevect);
%--------------------------------------------------------------------------
%-------------------------------------------------------------------------
function VIIDEOscoreval = computefinalscore(VIIDEOscorevect)
tpscore = (VIIDEOscorevect);
tpscore_shifted = circshift(tpscore,[1 0]);
change_score = abs(tpscore_shifted -tpscore);
VIIDEOscoreval = [nanmean(tpscore)+nanmean(change_score)];
%-------------------------------------------------------------------------
function VIIDEOscorevect = computeVIIDEOscorevector(param)
len = size(param,2)-1;
gap = floor(len/10);
VIIDEOscorevect = [];
for itr = 1:round(gap/2):len
f1_cum = [];
f2_cum = [];
for itr_param = itr:min(itr+gap,len)
low_Fr1 = [param(itr_param).featvect(:,3:14) ];
low_Fr2 = [param(itr_param+1).featvect(:,3:14)];
high_Fr1 = [param(itr_param).featvect(:,17:28) ];
high_Fr2 = [param(itr_param+1).featvect(:,17:28)];
vec1 = abs(low_Fr1 - low_Fr2);
vec2 = abs(high_Fr1- high_Fr2);
[IDX col] = find(isinf(vec1)|isnan(vec1)|...
isinf(vec2)|isnan(vec2));
vec1(IDX,:) = [];
vec2(IDX,:) = [];
if(~isempty(vec1))
f1_cum = [f1_cum; vec1];
f2_cum = [f2_cum; vec2];
end
end
if(~isempty(f1_cum))
C = diag(corr(f1_cum,f2_cum));
VIIDEOscorevect = [ VIIDEOscorevect;mean(C(:))];
end
end
%--------------------------------------------------------------------------
function [featvect] = computeVIIDEOfeaturevector(ydis1,ydis2, ...
blocksizerow,blocksizecol,blockrowoverlap,blockcoloverlap,filtlength)
warning('off')
shifts = [1 0; 0 1; 1 1; 1 -1];
window = fspecial('gaussian',filtlength,mean(filtlength)/6);
window = window/sum(sum(window));
featvect = [];
temporalsignal = ydis1-ydis2;
for itr =1:2
X = temporalsignal;
mu_X = imfilter(X,window,'replicate');
mu_sq = mu_X.*mu_X;
sigma_X = sqrt(abs(imfilter(X.*X,window,'replicate')- mu_sq));
structdis = (X-mu_X)./(sigma_X+1);
feat = computefeatvect(structdis,blocksizerow,...
blocksizecol,blockrowoverlap,blockcoloverlap);
featvect = [featvect feat(:,1) (feat(:,2)+feat(:,3))/2];
for itr_shift = 1:4
structdis_shifted = circshift(structdis,shifts(itr_shift,:));
feat = computefeatvect(structdis.*structdis_shifted, ...
blocksizerow,blocksizecol,...
blockrowoverlap,blockcoloverlap);
featvect = [featvect feat];
end
temporalsignal = mu_X;
end
%--------------------------------------------------------------------------
function [feat] = computefeatvect(structdis,blocksizerow,blocksizecol,...
blockrowoverlap,blockcoloverlap)
featnum = 3;
feat = blkproc(structdis,[blocksizerow blocksizecol],...
[ blockrowoverlap blockcoloverlap],@estimateaggdparam);
feat = reshape(feat,[featnum size(feat,1)*size(feat,2)/featnum]);
feat = feat';
feat = [feat(:,1) feat(:,2) feat(:,3)];
%--------------------------------------------------------------------------
function feat = estimateaggdparam(vec)
vec = vec(:);
if(sum(abs(vec(:))))
gam = 0.2:0.01:5;
r_gam = ((gamma(2./gam)).^2)./(gamma(1./gam).*gamma(3./gam));
leftstd = sqrt(mean((vec(vec<0)).^2));
rightstd = sqrt(mean((vec(vec>0)).^2));
gammahat = leftstd/rightstd;
rhat = (mean(abs(vec)))^2/mean((vec).^2);
rhatnorm = (rhat*(gammahat^3 +1)*(gammahat+1))/((gammahat^2 +1)^2);
[min_difference,...
array_position] = min((r_gam - rhatnorm).^2);
alpha = gam(array_position);
betal = leftstd *sqrt(gamma(1/alpha)/gamma(3/alpha));
betar = rightstd*sqrt(gamma(1/alpha)/gamma(3/alpha));
feat = [alpha;betal;betar];
else
feat = [inf; inf ; inf];
end
%--------------------------------------------------------------------------
function [y1 y2] = readframe(vidfilename, framenum,height,width)
fid = fopen(vidfilename);
fseek(fid,(framenum-1)*width*height*1.5,'bof');
y1 = fread(fid,width*height, 'uchar')';
y1 = reshape(y1,[width height]);
y1 = y1';
fseek(fid,(framenum)*width*height*1.5,'bof');
y2 = fread(fid,width*height, 'uchar')';
y2 = reshape(y2,[width height]);
y2 = y2';
fclose(fid);
%--------------------------------------------------------------------------