source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/image3dstiching/Refinement/CorrMatchPointsGivenOcclusion.m @ 37

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

Added original make3d

File size: 6.4 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 [ Matches]=CorrMatchPointsGivenOcclusion( ...
40                defaultPara, Pair, GlobalScale,...
41                POriReprojM1, FieldOccluPix1,PointPix1,...
42                POriReprojM2, FieldOccluPix2,PointPix2,...
43                ImgInfo1, ImgInfo2, ImgScale1, ImgScale2, ...
44                FlagEarlyStopCorrMatchPointsGivenOcclusion)
45
46% This function perform correlation matches given Occlusion info
47
48if nargin < 12
49        FlagEarlyStopCorrMatchPointsGivenOcclusion = 0;
50end
51PostFixStrAfter = 'CorrMatches';
52Img1 = ImgInfo1.ExifInfo.IDName
53Img2 = ImgInfo2.ExifInfo.IDName
54I1=imreadbw([defaultPara.Fdir '/pgm/' Img1 '.pgm']); % function from sift
55I2=imreadbw([defaultPara.Fdir '/pgm/' Img2 '.pgm']); % function from sift               
56
57depthratioMin = 0.01;
58depthratioMax = 100;
59
60    if ~isempty(Pair.lamda)
61        depthratio = Pair.lamda(1,:)./Pair.lamda(2,:);
62        % Min add to remove outliers (should be already removed when doing PoseEst.m)
63        Inliers = depthratio > depthratioMin & depthratio < depthratioMax;
64        depthratio = depthratio(Inliers);
65        if ~isempty(depthratio)
66                maxRatio = max(depthratio);
67                minRatio = min(depthratio);
68        else
69                maxRatio = depthratioMax;
70                minRatio = depthratioMin;
71        end
72    else
73        maxRatio = max([GlobalScale(1)/GlobalScale(2) GlobalScale(2)/GlobalScale(1)]);
74        minRatio = 1/maxRatio;
75    end
76
77    [Matches1 CoeffM1 Inliers1]=CorrolationMatch( defaultPara, Pair, I1, I2, PointPix1, POriReprojM1, FieldOccluPix1, [minRatio maxRatio]);
78    if defaultPara.Flag.FlagRefinementDisp
79        disp('Start Reverse CorrolationMatches Hold on');
80%       whos
81    end
82
83    Pair2_1.R = Pair.R';
84    Pair2_1.T = -Pair.R'*Pair.T;
85    [Matches2 CoeffM2 Inliers2]=CorrolationMatch( defaultPara, Pair2_1, I2, I1, PointPix2, POriReprojM2, FieldOccluPix2, [1/maxRatio 1/minRatio]);
86    if defaultPara.Flag.FlagRefinementDisp
87        disp('CorrolationMatch.m Finished');
88    end
89
90    Matches1 = Matches1(:,Inliers1);
91    Matches2 = Matches2(:,Inliers2);
92    CoeffM1 = CoeffM1(:,Inliers1);
93    CoeffM2 = CoeffM2(:,Inliers2);
94         
95    % Check if the Matches are not mutual discard the one with less Coeff(Cross-Corrolation value) ===============
96    Matches = [ Matches1 [Matches2(3:4,:); Matches2(1:2,:)]];
97    CoeffM = [ CoeffM1 CoeffM2];
98        % Min used different algorithm than SurFeature Matches
99        [Inliers] = CleanMatch(Matches, CoeffM(1,:)); % choose the matches with higher Coeff is the matches is not mutual
100        [InliersReverse] = CleanMatch(Matches([3 4 1 2],Inliers), CoeffM(1,Inliers)); % choose the matches with higher Coeff is the matches is not mutual
101        Inliers = Inliers(InliersReverse);
102        Matches = Matches(:,Inliers);
103        CoeffM = CoeffM(:,Inliers);
104
105    if defaultPara.Flag.FlagRefinementDisp
106        figure; plotmatches(I1,I2,Matches(1:2,:), Matches(3:4,:),repmat(1:size(Matches,2),2,1), 'Stacking','v','Interactive', 3);
107    end
108
109%    save([defaultPara.Fdir '/data/' Img1 '_' Img2 '_' PostFixStrAfter 'BeforeFiltering.mat'],'Matches','CoeffM');
110
111    % use Coeff as threshould to filter out error matches
112    CoeffMask = CoeffM(1,:) > defaultPara.CoeffMThre;
113    [inlier, Residual] = EpipoPrune(defaultPara, Pair, Matches, ImgScale1);
114    EpipolarResidualMask = Residual < defaultPara.ResidualThre;
115    CoeffRationMask = CoeffM(2,:)./CoeffM(1,:) < defaultPara.coeffratioThre;
116    CoeffRationMask( CoeffM(1,:) == 0) = false;% CoeffM(1,:) == 0 means not satisfy the epipolar constrain
117    Mark = CoeffMask & CoeffRationMask & EpipolarResidualMask;
118
119%    save([defaultPara.Fdir '/data/' Img1 '_' Img2 '_' PostFixStrAfter '.mat'],'Matches','CoeffM','Mark');
120
121if FlagEarlyStopCorrMatchPointsGivenOcclusion
122        Matches = Matches(:,Mark);
123    save([defaultPara.Fdir '/data/' Img1 '_' Img2 '_' PostFixStrAfter '.mat'],'Matches','CoeffM');
124        return;
125end
126    % =======================================================================
127    if ~isempty(Matches(:,Mark))
128        tempf1 = Matches(1:2,Mark);
129        tempf2 = Matches(3:4,Mark);
130        x_calib = [ inv(defaultPara.InrinsicK1)*[ tempf1; ones(1,size(tempf1,2))];...
131        inv(defaultPara.InrinsicK2)*[ tempf2; ones(1,size(tempf2,2))]];
132        [ lamda1 lamda2 Error] = triangulation( defaultPara, Pair.R, Pair.T, x_calib);
133        % notice lamda re-scale to local model scale
134        lamda1 = lamda1./GlobalScale(1);
135        lamda2 = lamda2./GlobalScale(2);
136        % Storage the match result for later ReInference
137        AddMatch2Model(defaultPara, defaultPara.Wrlname, lamda1, Matches(1:2,Mark), ImgInfo1, ImgScale1, Img1Index, Img2Index, PostFixStrAfter, Error);
138        AddMatch2Model(defaultPara, defaultPara.Wrlname, lamda2, Matches(3:4,Mark), ImgInfo2, ImgScale2, Img2Index, Img1Index, PostFixStrAfter, Error);
139        % Storage the New Matches                   
140%       if defaultPara.Flag.FlagRefinementDisp
141                disp('Storaging Occlusion Surf Features Matches');
142                save([defaultPara.Fdir '/data/' Img1 '_' Img2 '_' PostFixStrAfter '.mat'],'Matches','CoeffM','Error','Mark');
143%       end
144    end
145
146return;
Note: See TracBrowser for help on using the repository browser.