-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPropagateEven.m
67 lines (62 loc) · 3.02 KB
/
PropagateEven.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
function [offsets,matchTable] = PropagateEven(patchTable,offsets,matchTable)
vecLength = size(patchTable,4)*size(patchTable,5);
kmatch = size(patchTable,3);
flipped = [1 kmatch:-1:2];
for i = size(patchTable,1):-1:2
for j = size(patchTable,2):-1:2
for k = kmatch:-1:1
ii = i + offsets(i,j,k,1);
jj = j + offsets(i,j,k,2);
kk = offsets(i,j,k,3);
% Try to propagate match up
if(ii - 1 >= 1)
d2 = sum(sum((patchTable(i-1,j,kk,:) - patchTable(ii-1,jj,kk,:)).^2))/vecLength;
if(d2 < matchTable(i-1,j,2))
km = matchTable(i-1,j,1);
offsets(i-1,j,km,:) = [ii-i jj-j kk d2];
[maxVal,maxInd] = max(offsets(i-1,j,:,4));
matchTable(i-1,j,1:2) = [maxInd maxVal];
end
if(d2 < matchTable(ii-1,jj,2))
km = matchTable(ii-1,jj,1);
offsets(ii-1,jj,km,:) = [i-ii,j-jj,flipped(kk),d2];
[maxVal,maxInd] = max(offsets(ii-1,jj,:,4));
matchTable(ii-1,jj,1:2) = [maxInd maxVal];
end
end
% Try to propagate match up
if(jj - 1 >= 1)
d2 = sum(sum((patchTable(i,j-1,kk,:) - patchTable(ii,jj-1,kk,:)).^2))/vecLength;
if(d2 < matchTable(i,j-1,2))
km = matchTable(i,j-1,1);
offsets(i,j-1,km,:) = [ii-i jj-j kk d2];
[maxVal,maxInd] = max(offsets(i,j-1,:,4));
matchTable(i,j-1,1:2) = [maxInd maxVal];
end
if(d2 < matchTable(ii,jj-1,2))
km = matchTable(ii,jj-1,1);
offsets(ii,jj-1,km,:) = [i-ii,j-jj,flipped(kk),d2];
[maxVal,maxInd] = max(offsets(ii,jj-1,:,4));
matchTable(ii,jj-1,1:2) = [maxInd maxVal];
end
end
% Try to propagate match up and left
if(ii - 1 >= 1 && jj - 1 >= 1)
d2 = sum(sum((patchTable(i-1,j-1,kk,:) - patchTable(ii-1,jj-1,kk,:)).^2))/vecLength;
if(d2 < matchTable(i-1,j-1,2))
km = matchTable(i-1,j-1,1);
offsets(i-1,j-1,km,:) = [ii-i jj-j kk d2];
[maxVal,maxInd] = max(offsets(i-1,j-1,:,4));
matchTable(i-1,j-1,1:2) = [maxInd maxVal];
end
if(d2 < matchTable(ii-1,jj-1,2))
km = matchTable(ii-1,jj-1,1);
offsets(ii-1,jj-1,km,:) = [i-ii,j-jj,flipped(kk),d2];
[maxVal,maxInd] = max(offsets(ii-1,jj-1,:,4));
matchTable(ii-1,jj-1,1:2) = [maxInd maxVal];
end
end
end
end
end
end