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

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

Added original make3d

File size: 7.7 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 [model1 model2] = RedundentPlanePick(defaultPara, ImgInfo1, ImgInfo2, Pair, GlobalScale, ...
40                                Img1IndexTarget, Img2IndexField, Img2IndexTarget, Img1IndexField)
41
42% [model1 model2] = RedundentPlanePick(defaultPara, ImgInfo1, ImgInfo2, ...
43%                                Img1IndexTarget, Img2IndexField, Img2IndexTarget, Img1IndexField)
44
45ErareTargetFlag = 1;
46CheckOwnRayFlag = 1;
47ErodeRemoveRegionFlag = 1;
48
49% take out the Plane Parameter to check the orientationa==========================
50PlanePara1Target = ImgInfo1.Model.PlaneParaInfo.PlanePara(:,ImgInfo1.Model.PlaneParaInfo.Sup2Para(...
51                   ImgInfo1.Model.PlaneParaInfo.SupEpand(Img1IndexTarget)));
52PlanePara1Field = ImgInfo2.Model.PlaneParaInfo.PlanePara(:,ImgInfo2.Model.PlaneParaInfo.Sup2Para(...
53                   ImgInfo2.Model.PlaneParaInfo.SupEpand(Img2IndexField)));
54% correct Scale to Global Scale
55PlanePara1Target = PlanePara1Target/GlobalScale(1);
56PlanePara1Field = PlanePara1Field/GlobalScale(2);
57% Transfer Feild Plane Parameters into Target coordinate
58PlanePara1Field_Ori = PlanePara1Field;
59PlanePara1Field = Pair.R'*PlanePara1Field./repmat(1- Pair.T'*PlanePara1Field, 3, 1);
60
61% normalized to unit vector
62PlanePara1Target = PlanePara1Target./repmat(sqrt( sum( PlanePara1Target.^2,1)), 3, 1);
63PlanePara1Field_Ori = PlanePara1Field_Ori./repmat(sqrt( sum( PlanePara1Field_Ori.^2,1)), 3, 1);
64PlanePara1Field = PlanePara1Field./repmat(sqrt( sum( PlanePara1Field.^2,1)), 3, 1);
65
66% Calculate the portion that align with the ray
67Ray1 = ImgInfo1.Model.PlaneParaInfo.Ray(:,:);
68PlanePara1Target2Ray = abs( sum(PlanePara1Target.*Ray1(:,Img1IndexTarget), 1) );
69if CheckOwnRayFlag
70        Ray1Field = ImgInfo2.Model.PlaneParaInfo.Ray(:,:);
71        PlanePara1Field2Ray = abs( sum(PlanePara1Field_Ori.*Ray1Field(:,Img2IndexField), 1) );
72else
73        PlanePara1Field2Ray = abs( sum(PlanePara1Field.*Ray1(:,Img1IndexTarget), 1) );
74end
75
76
77PlanePara2Target = ImgInfo2.Model.PlaneParaInfo.PlanePara(:,ImgInfo2.Model.PlaneParaInfo.Sup2Para(...
78                    ImgInfo2.Model.PlaneParaInfo.SupEpand(Img2IndexTarget)));
79PlanePara2Field = ImgInfo1.Model.PlaneParaInfo.PlanePara(:,ImgInfo1.Model.PlaneParaInfo.Sup2Para(...
80                    ImgInfo1.Model.PlaneParaInfo.SupEpand(Img1IndexField)));
81
82% correct Scale to Global Scale
83PlanePara2Target = PlanePara2Target/GlobalScale(2);
84PlanePara2Field = PlanePara2Field/GlobalScale(1);
85% Transfer Feild Plane Parameters into Target coordinate
86PlanePara2Field_Ori = PlanePara2Field;
87PlanePara2Field = Pair.R*PlanePara2Field./repmat(1- ( -Pair.R'*Pair.T )'*PlanePara2Field, 3, 1);
88
89% normalized to unit vector
90PlanePara2Target = PlanePara2Target./repmat(sqrt( sum( PlanePara2Target.^2,1)), 3, 1);
91PlanePara2Field_Ori = PlanePara2Field_Ori./repmat(sqrt( sum( PlanePara2Field_Ori.^2,1)), 3, 1);
92PlanePara2Field = PlanePara2Field./repmat(sqrt( sum( PlanePara2Field.^2,1)), 3, 1);
93
94% Calculate the portion that align with the ray
95Ray2 = ImgInfo2.Model.PlaneParaInfo.Ray(:,:);
96PlanePara2Target2Ray =  sum(PlanePara2Target.*Ray2(:,Img2IndexTarget), 1) ;
97if CheckOwnRayFlag
98        Ray2Field = ImgInfo1.Model.PlaneParaInfo.Ray(:,:);
99        PlanePara2Field2Ray = abs( sum(PlanePara2Field_Ori.*Ray2Field(:,Img1IndexField), 1) );
100else
101        PlanePara2Field2Ray =  sum(PlanePara2Field.*Ray2(:,Img2IndexTarget), 1) ;
102end
103
104% ===============================================================================
105
106% Pick out the Plane has a bigger normalized PlanPrameter of the Ray
107if ErareTargetFlag
108        Img1IndexTargetOutliers = abs(PlanePara1Target2Ray) < abs(PlanePara1Field2Ray);
109else
110        Img1IndexTargetOutliers = Inf < abs(PlanePara1Field2Ray);
111end
112Img2IndexFieldOutliers = ~Img1IndexTargetOutliers;
113
114if ErareTargetFlag
115        Img2IndexTargetOutliers = abs(PlanePara2Target2Ray) < abs(PlanePara2Field2Ray);
116else
117        Img2IndexTargetOutliers = Inf < abs(PlanePara2Field2Ray);
118end
119Img1IndexFieldOutliers = ~Img2IndexTargetOutliers;
120
121
122if ErodeRemoveRegionFlag
123   OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri));
124   OriSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0;
125   se = strel('ball',5,5);
126   OriSup = imdilate(OriSup,se);
127   Img1IndexTargetNew = find(OriSup == 0);
128   
129   OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri));
130   OriSup(  Img2IndexField( Img2IndexFieldOutliers)) = 0;
131   se = strel('ball',5,5);
132   OriSup = imdilate(OriSup,se);
133   Img2IndexFieldNew = find(OriSup == 0);
134   
135   OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri));
136   OriSup(  Img2IndexTarget( Img2IndexTargetOutliers)) = 0;
137   se = strel('ball',5,5);
138   OriSup = imdilate(OriSup,se);
139   Img2IndexTargetNew = find(OriSup == 0);
140   
141   OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri));
142   OriSup( Img1IndexField( Img1IndexFieldOutliers)) = 0;
143   se = strel('ball',5,5);
144   OriSup = imdilate(OriSup,se);
145   Img1IndexFieldNew = find(OriSup == 0);
146end   
147
148% Modify the Sup to 0 so that it won't rendered
149tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri;
150tempSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0;
151tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end);
152tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:);
153ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup;
154
155tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri;
156tempSup( Img2IndexField( Img2IndexFieldOutliers)) = 0;
157tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end);
158tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:);
159ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup;
160
161tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri;
162tempSup( Img2IndexTarget( Img2IndexTargetOutliers)) = 0;
163tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end);
164tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:);
165ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup;
166
167tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri;
168tempSup( Img1IndexField( Img1IndexFieldOutliers)) = 0;
169tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end);
170tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:);
171ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup;
172
173
174% assign model1 and model2
175model1 = ImgInfo1.Model;
176model2 = ImgInfo2.Model;
177
178return;
179
Note: See TracBrowser for help on using the repository browser.