-
Notifications
You must be signed in to change notification settings - Fork 3
/
dpMatchPlanes.m
96 lines (81 loc) · 1.89 KB
/
dpMatchPlanes.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
function optimalAssignmentIndices = dpMatchPlanes(imSubSeq,imSeq,scaleRange,vertDispRange,initialMatch,maxShift,displayProgress,displayOutput)
nSS = length(imSubSeq);
nS = length(imSeq);
CR = zeros(nSS,nS);
lCR = cell(1,nSS*nS);
ij = cell(nSS*nS,2);
count = 0;
for i = 1:nSS
for j = 1:nS
count = count+1;
ij{count,1} = i;
ij{count,2} = j;
end
end
if displayProgress
pfpb = pfpbStart(count);
end
parfor idx = 1:count
if displayProgress
pfpbUpdate(pfpb);
end
i = ij{idx,1};
j = ij{idx,2};
imSS = imSubSeq{i};
imS = imSeq{j};
if abs(initialMatch(i)-j) > maxShift
c2 = 0;
else
[~,c2] = imscalereg(imSS,imS,scaleRange,scaleRange,vertDispRange);
end
% [TI,c2] = imscalereg(imSS,imS,rg,rg);
% imshowlt(imadjust(TI),imadjust(imS))
% pause, close all
lCR{idx} = c2;
end
count = 0;
for i = 1:nSS
for j = 1:nS
count = count+1;
CR(i,j) = lCR{count};
end
end
C = 1-CR;
[nRows, nCols] = size(C);
if nRows < 2
error('not enough rows')
end
if nCols < 2
error('not enough cols')
end
pathCosts = zeros(size(C));
pathCosts(1,:) = C(1,:);
predecessors = nan(size(C));
for i = 2:nRows
for j = 1:nCols
localCosts = pathCosts(i-1,:);
localCosts(j:end) = Inf;
[m,im] = min(localCosts);
updatedCost = m+C(i,j);
pathCosts(i,j) = updatedCost;
predecessors(i,j) = im;
end
end
[~,im] = min(pathCosts(nRows,:));
cPath = zeros(nRows,1);
cPath(nRows) = im;
for i = nRows-1:-1:1
cPath(i) = predecessors(i+1,cPath(i+1));
end
optimalAssignmentIndices = cPath;
if displayOutput
P = zeros(size(C));
for i = 1:nRows
P(i,cPath(i)) = 1;
end
subplot(2,1,1)
imshow(imresize(CR,10,'nearest')), title('correlations, mapped to [0, 1]')
subplot(2,1,2)
imshow(imresize(P,10,'nearest')), title('optimal assignment')
end
end