Line | |
---|
1 | % |
---|
2 | % Function Mnorm=normalize(M,I) |
---|
3 | % |
---|
4 | % normalizes M by dividing each point by its homogenous coordinate |
---|
5 | % (these coordinates equal to ones afterwards). |
---|
6 | % |
---|
7 | % Parameter I can be omitted for complete scenes. |
---|
8 | |
---|
9 | function Mnorm=normalize(M,I) |
---|
10 | |
---|
11 | m=size(M,1)/3; |
---|
12 | n=size(M,2); |
---|
13 | |
---|
14 | if nargin < 2 |
---|
15 | I=ones(m,n); |
---|
16 | end |
---|
17 | |
---|
18 | Mnorm(1:3*m, 1:n) = M; % There are two reasons for this. (i) Make NaN the |
---|
19 | % unknown data thus the whole matrix has to be filled |
---|
20 | % by NaNs. (ii) Sometimes it happens that when there |
---|
21 | % is a missing data in the last column(s), the |
---|
22 | % column(s) disapppears. |
---|
23 | |
---|
24 | known = find(I); |
---|
25 | big_enough = known(find( abs(M(known*3)) > eps )); |
---|
26 | if m == 1, big_enough = big_enough'; end |
---|
27 | |
---|
28 | if ~isempty(big_enough) |
---|
29 | div_by = repmat(M(big_enough*3)',3,1); |
---|
30 | Mnorm(k2i(big_enough)) = M(k2i(big_enough)) ./ div_by(:); |
---|
31 | end |
---|
32 | |
---|
33 | Mnorm(setdiff(known, big_enough)*3) = 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.