-
Notifications
You must be signed in to change notification settings - Fork 1
/
process6.m
273 lines (269 loc) · 7.92 KB
/
process6.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
function [saliency,smooth] = process6(Vbg1,x,y)
%%
%k=4 Create a matrix of little square
%Vb will contain the 3D matrix with background modification
Vb=Vbg1;
k=4;
num=256/k;
fprintf('%d..\n',num*num);
quad=num*num;
%cut the work variable Vb into "quad" (in this case 4096) square
%create an element containing "k" square scrollable by the third dimension.
%Every square has three channels scrollable by the second dimension.
%First dimension select the single square
%This process is applied to all k values
%{
%first dimension of the first channel
Vpatch4(:,:,1,1)=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
%second dimension of the first channel
Vpatch4(:,:,1,2)=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
%third dimension of the first channel
Vpatch4(:,:,1,3)=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
%}
pos=0;
for z = 1:num
for w = 1:num
pos=pos+1;
for i = 1:k
for j = 1:k
%Every pixels is assigned to the appropriate square for all
%channels
Vpatch4(i,j,1,pos)=Vb(i+((w-1)*k),j+((z-1)*k),1);
Vpatch4(i,j,2,pos)=Vb(i+((w-1)*k),j+((z-1)*k),2);
Vpatch4(i,j,3,pos)=Vb(i+((w-1)*k),j+((z-1)*k),3);
end
end
%To verify the correct cut you can show here for example the L channel of the "pos" square
%imsshow(Vpatch4(:,:,1,pos))
end
end
%
%Mean value of all square k=4
meanL4=cat(3,zeros(num));
meanA4=cat(3,zeros(num));
meanB4=cat(3,zeros(num));
for pos = 1 : quad
for i = 1:k
for j = 1:k
%sum each pixel of square "pos"
meanL4(pos)=meanL4(pos)+Vpatch4(i,j,1,pos);
meanA4(pos)=meanL4(pos)+Vpatch4(i,j,2,pos);
meanB4(pos)=meanL4(pos)+Vpatch4(i,j,3,pos);
end
end
%calculate the mean value of each square and assign this value to the
%"pos" element of the appropiate matrix
meanL4(pos)=meanL4(pos)/(k*k);
meanA4(pos)=meanA4(pos)/(k*k);
meanB4(pos)=meanB4(pos)/(k*k);
end
%The two cycles guided by w and z are used to hold the patch that you
%want to compute the salience
%Other two cycles scroll all patches every time
SAL4=cat(3,zeros(num));
for w = 1 :num
for z = 1:num
for i = 1 :num
for j = 1:num
%Distance is computed every time between the
%patch that you want to compute salience and the patch you are comparing
%EXAMPLE
%|patch1||patch2||patch3|
%I chose the distance between "patch1" and "patch3" to be 2.
%So I used a distance NOT in terms of pixels.
%If you need the pixels distance, you have to simply multiply this term by k
d=sqrt((w-i)^2+(z-j)^2);
%Salience depends also on the chromatic distance of the
%compared patches
sal4=sqrt((meanL4(w,z)-meanL4(i,j))^2+(meanA4(w,z)-meanA4(i,j))^2+(meanB4(w,z)-meanB4(i,j))^2);
sal4=sal4/(1+d);
%Finally I add to the summation this term of salience relative to the (w,z) patch
SAL4(w,z)=SAL4(w,z)+sal4;
end
end
end
end
%%
%k=8
k=8;
num=256/k;
fprintf('%d..\n',num*num);
quad=num*num;
pos=0;
for z = 1:num
for w = 1:num
pos=pos+1;
for i = 1:k
for j = 1:k
Vpatch8(i,j,1,pos)=Vb(i+((w-1)*k),j+((z-1)*k),1);
Vpatch8(i,j,2,pos)=Vb(i+((w-1)*k),j+((z-1)*k),2);
Vpatch8(i,j,3,pos)=Vb(i+((w-1)*k),j+((z-1)*k),3);
end
end
end
end
%
%Mean value of all square k=8
meanL8=cat(3,zeros(num));
meanA8=cat(3,zeros(num));
meanB8=cat(3,zeros(num));
for pos = 1 : quad
for i = 1:k
for j = 1:k
meanL8(pos)=meanL8(pos)+Vpatch8(i,j,1,pos);
meanA8(pos)=meanL8(pos)+Vpatch8(i,j,2,pos);
meanB8(pos)=meanL8(pos)+Vpatch8(i,j,3,pos);
end
end
meanL8(pos)=meanL8(pos)/(k*k);
meanA8(pos)=meanA8(pos)/(k*k);
meanB8(pos)=meanB8(pos)/(k*k);
end
SAL8=cat(3,zeros(num));
for w = 1 :num
for z = 1:num
for i = 1 :num
for j = 1:num
d=sqrt((w-i)^2+(z-j)^2);
sal8=sqrt((meanL8(w,z)-meanL8(i,j))^2+(meanA8(w,z)-meanA8(i,j))^2+(meanB8(w,z)-meanB8(i,j))^2);
sal8=sal8/(1+d);
SAL8(w,z)=SAL8(w,z)+sal8;
end
end
end
end
%%
%k=16
k=16;
num=256/k;
fprintf('%d..\n',num*num);
quad=num*num;
pos=0;
for z = 1:num
for w = 1:num
pos=pos+1;
for i = 1:k
for j = 1:k
Vpatch16(i,j,1,pos)=Vb(i+((w-1)*k),j+((z-1)*k),1);
Vpatch16(i,j,2,pos)=Vb(i+((w-1)*k),j+((z-1)*k),2);
Vpatch16(i,j,3,pos)=Vb(i+((w-1)*k),j+((z-1)*k),3);
end
end
end
end
%
%Mean value of all square k=16
meanL16=cat(3,zeros(num));
meanA16=cat(3,zeros(num));
meanB16=cat(3,zeros(num));
for pos = 1 : quad
for i = 1:k
for j = 1:k
meanL16(pos)=meanL16(pos)+Vpatch16(i,j,1,pos);
meanA16(pos)=meanL16(pos)+Vpatch16(i,j,2,pos);
meanB16(pos)=meanL16(pos)+Vpatch16(i,j,3,pos);
end
end
meanL16(pos)=meanL16(pos)/(k*k);
meanA16(pos)=meanA16(pos)/(k*k);
meanB16(pos)=meanB16(pos)/(k*k);
end
SAL16=cat(3,zeros(num));
for w = 1 :num
for z = 1:num
for i = 1 :num
for j = 1:num
d=sqrt((w-i)^2+(z-j)^2);
sal16=sqrt((meanL16(w,z)-meanL16(i,j))^2+(meanA16(w,z)-meanA16(i,j))^2+(meanB16(w,z)-meanB16(i,j))^2);
sal16=sal16/(1+d);
SAL16(w,z)=SAL16(w,z)+sal16;
end
end
end
end
%%
%k=32
k=32;
num=256/k;
fprintf('%d..\n',num*num);
quad=num*num;
pos=0;
for z = 1:num
for w = 1:num
pos=pos+1;
for i = 1:k
for j = 1:k
Vpatch32(i,j,1,pos)=Vb(i+((z-1)*k),j+((w-1)*k),1);
Vpatch32(i,j,2,pos)=Vb(i+((z-1)*k),j+((w-1)*k),2);
Vpatch32(i,j,3,pos)=Vb(i+((z-1)*k),j+((w-1)*k),3);
end
end
end
end
%
%Mean value of all square k=32
meanL32=cat(3,zeros(num));
meanA32=cat(3,zeros(num));
meanB32=cat(3,zeros(num));
for pos = 1 : quad
for i = 1:k
for j = 1:k
meanL32(pos)=meanL32(pos)+Vpatch32(i,j,1,pos);
meanA32(pos)=meanL32(pos)+Vpatch32(i,j,2,pos);
meanB32(pos)=meanL32(pos)+Vpatch32(i,j,3,pos);
end
end
meanL32(pos)=meanL32(pos)/(k*k);
meanA32(pos)=meanA32(pos)/(k*k);
meanB32(pos)=meanB32(pos)/(k*k);
end
SAL32=cat(3,zeros(num));
for w = 1 :num
for z = 1:num
for i = 1 :num
for j = 1:num
d=sqrt((w-i)^2+(z-j)^2);
sal32=sqrt((meanL32(w,z)-meanL32(i,j))^2+(meanA32(w,z)-meanA32(i,j))^2+(meanB32(w,z)-meanB32(i,j))^2);
sal32=sal32/(1+d);
SAL32(w,z)=SAL32(w,z)+sal32;
end
end
end
end
%%
%resize all saliency maps to the original size using bilinear interpolation
sal4 = bilinearInterpolation(SAL4, [256 256]);
sal8 = bilinearInterpolation(SAL8, [256 256]);
sal16 = bilinearInterpolation(SAL16, [256 256]);
sal32 = bilinearInterpolation(SAL32, [256 256]);
saliency=cat(3,zeros(256));
smooth=cat(3,zeros(256));
%%
%cut the added pixels
sal4 = sal4(1:x,1:y);
sal8 = sal8(1:x,1:y);
sal16 = sal16(1:x,1:y);
sal32 = sal32(1:x,1:y);
saliency=saliency(1:x,1:y);
smooth=smooth(1:x,1:y);
%%
%make the weighted sum of the different saliency maps
saliency=saliency+sal4/4;
saliency=saliency+sal8/4;
saliency=saliency+sal16/4;
saliency=saliency+sal32/4;
%create the smoothed version of the saliency map
smooth=medfilt2(saliency, [25 25]);
end