1 | function A = impute(M,INC) |
---|
2 | % This will implement the imputation method of Tomasi and Kanade. |
---|
3 | % We'll use a very simple, restricted plan to choose where to |
---|
4 | % start and what direction to grow in. We begin with a rectangle |
---|
5 | % in the upper left corner that is fully occupied, and grow one |
---|
6 | % row or column at a time. We assume there is an obvious maximal |
---|
7 | % rectangle to begin with, and that we can only grow in one direction |
---|
8 | % at each step. This will be useful for experiments with simple occlusion patterns. |
---|
9 | [numrows,numcols] = size(M); |
---|
10 | |
---|
11 | curcol = 0; |
---|
12 | i = 1; |
---|
13 | while (i <= numcols & INC(1,i)), |
---|
14 | i = i + 1; |
---|
15 | end |
---|
16 | curcol = i - 1; |
---|
17 | |
---|
18 | currow = 0; |
---|
19 | i = 1; |
---|
20 | while (i <= numrows & all(INC(i,1:curcol))), |
---|
21 | i = i+1; |
---|
22 | end |
---|
23 | currow = i - 1; |
---|
24 | |
---|
25 | curM = M(1:currow,1:curcol); |
---|
26 | while (currow < numrows | curcol < numcols) |
---|
27 | extend_right = 0; |
---|
28 | extend_down = 0; |
---|
29 | if (curcol < numcols & sum(INC(1:currow,min(numcols,curcol+1))) > 3) |
---|
30 | extend_right = 1; |
---|
31 | end |
---|
32 | if (currow < numrows & sum(INC(min(numrows,currow+1),1:curcol)) > 3) |
---|
33 | extend_down = 1; |
---|
34 | end |
---|
35 | if ~(extend_down | extend_right) |
---|
36 | error('No extension available'); |
---|
37 | end |
---|
38 | [T, P] = tk_affine(curM); |
---|
39 | % Note that if extension can go in either direction, we extend right. |
---|
40 | if extend_right |
---|
41 | v = find(INC(1:currow,curcol+1)); |
---|
42 | curM = [curM, T*(T(v,:)\M(v,curcol+1))]; |
---|
43 | curcol = curcol+1; |
---|
44 | else |
---|
45 | v = find(INC(currow+1,1:curcol)); |
---|
46 | curM = [curM; (M(currow+1,v)/P(:,v))*P]; |
---|
47 | currow = currow+1; |
---|
48 | end |
---|
49 | end |
---|
50 | A = curM; |
---|