source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/image3dstiching/match/TrackBuilding.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.3 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function [ track]=TrackBuilding(Matches)
40
41% This function given the Matches between all pairs of images
42% generate the track without any inconsistent (delete the track with any inconsistency):
43% in that one image observes multiple features in the track
44
45% add image in order from img1, img2, to imgxxx
46% When add new image look for matches between added images
47% and maintaining the matches
48
49NumImages = size(Matches,1);
50track = sparse(0,NumImages);
51InConsistMatchesBin = cell(1,NumImages);
52NumTrack = size( track,1);
53for i = 1:NumImages
54        if i ==1 % can build track with only one image
55                continue;
56        end
57        for j = 1:i-1
58%               i
59%        j
60                % Skip if Matches(j,i).Index is empty
61                if isempty(Matches(j,i).Index)
62                        continue;
63                end
64
65                % Clean the Matches using InConsistMatchesBin
66                NumInconsistMatchesOfJ = size(InConsistMatchesBin{j},1);
67                if NumInconsistMatchesOfJ ~=0
68                        NumMatces = size(Matches(j,i).Index, 2);
69                        DeleteMark = sum(repmat( Matches(j,i).Index, NumInconsistMatchesOfJ, 1) == repmat(InConsistMatchesBin{j}, 1, NumMatces), 1) ~= 0;
70                        Matches(j,i).Index(DeleteMark) = [];
71                        Matches(i,j).Index(DeleteMark) = [];
72                end
73
74                NumMatces = size(Matches(j,i).Index, 2);
75                % editing existing track
76                if NumTrack ~=0
77                        Ptr = (repmat(track(:,j), 1, NumMatces) == ...
78                                repmat( Matches(j,i).Index, NumTrack, 1));
79                        Target = repmat( Matches(i,j).Index, NumTrack, 1);
80            NewTarget = sparse(NumTrack, 1);
81                        NewTarget(sum(Ptr,2)~=0) = sum( Target(Ptr), 2);
82            Target = NewTarget;
83                        Matches_for_new_track_I = setdiff(Matches(i,j).Index, Target');
84                        % check consistency
85                        InConsistMark = (Target ~= track(:,i)) & (track(:,i) ~= 0);
86                        track(:,i) = Target;
87                        % maintina the InConsistMatchesBin
88            if ~all(InConsistMark==0)
89                InConsistMatchesBin{j} = union(InConsistMatchesBin{j}, track(InConsistMark,j));
90                InConsistMatchesBin{i} = track(InConsistMark,i);
91                track(InConsistMark,:) = [];
92            end
93                else
94                        Matches_for_new_track_I = Matches(i,j).Index;
95                end
96
97                % add new track
98                NumNewTrack = length(Matches_for_new_track_I);
99                Matches_for_new_track_mark_I = sum( repmat( Matches(i,j).Index, NumNewTrack, 1) ==...
100                                                        repmat( Matches_for_new_track_I', 1, NumMatces), 1) ~=0;
101                NewTrack = sparse(NumNewTrack, NumImages);
102                NewTrack(:,j) = Matches(j,i).Index(Matches_for_new_track_mark_I)';
103                NewTrack(:,i) = Matches(i,j).Index(Matches_for_new_track_mark_I)';
104                track = [track; NewTrack];
105               
106                % maintain Num of track
107                NumTrack = size( track,1);
108        end
109end
Note: See TracBrowser for help on using the repository browser.