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

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

Added original make3d

File size: 8.1 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% Setup the Position3D in Global Scale
50Position3D1 = ImgInfo1.Model.PlaneParaInfo.Position3DFited = permute( ModelInfo1.Model.PlaneParaInfo.Position3DFited*GlobalScale(1),[ 3 1 2]);
51Position3D2 = ImgInfo2.Model.PlaneParaInfo.Position3DFited = permute( ModelInfo1.Model.PlaneParaInfo.Position3DFited*GlobalScale(2),[ 3 1 2]);
52
53% Pick out the Ray
54Ray1 = ImgInfo1.Model.PlaneParaInfo.Ray(:,:);
55Ray2 = ImgInfo2.Model.PlaneParaInfo.Ray(:,:);
56
57% Calculate the Target Surface Norm
58TargetFaceSetPoints1 = Position3D1(:,Img1IndexTarget(:));
59TargerFaceSetPoints1 = reshape(TargerFaceSetPoints1, 3, 3, []);
60TargerFaceSetTwoEdge1 = TargerFaceSetPoints1(:,1:2,:) - repmat( TargerFaceSetPoints1(:,3,:),[ 1 2 1]);
61TargerSrufaceNormalVector1 = cross( TargerFaceSetTwoEdge1(:,1,:), TargerFaceSetTwoEdge1(:,2,:), 1);
62TargerSrufaceNormalVector1 = permute( TargerSrufaceNormalVector1./repmat( sqrt( sum( TargerSrufaceNormalVector1.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget
63
64TargetFaceSetPoints2 = Position3D2(:,Img2IndexTarget(:));
65TargerFaceSetPoints2 = reshape(TargerFaceSetPoints2, 3, 3, []);
66TargerFaceSetTwoEdge2 = TargerFaceSetPoints2(:,1:2,:) - repmat( TargerFaceSetPoints2(:,3,:),[ 1 2 1]);
67TargerSrufaceNormalVector2 = cross( TargerFaceSetTwoEdge2(:,1,:), TargerFaceSetTwoEdge2(:,2,:), 1);
68TargerSrufaceNormalVector2 = permute( TargerSrufaceNormalVector2./repmat( sqrt( sum( TargerSrufaceNormalVector2.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget
69
70% Calculate the Field Surface Norm
71FieldFaceSetPoints1 = Position3D2(:,Img2IndexField(:));
72FieldFaceSetPoints1 = reshape(FieldFaceSetPoints1, 3, 3, []);
73FieldFaceSetTwoEdge1 = FieldFaceSetPoints1(:,1:2,:) - repmat( FieldFaceSetPoints1(:,3,:),[ 1 2 1]);
74FieldSrufaceNormalVector1 = cross( FieldFaceSetTwoEdge1(:,1,:), FieldFaceSetTwoEdge1(:,2,:), 1);
75FieldSrufaceNormalVector1 = permute( FieldSrufaceNormalVector1./repmat( sqrt( sum( FieldSrufaceNormalVector1.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget
76
77FieldFaceSetPoints2 = Position3D1(:,Img1IndexField(:));
78FieldFaceSetPoints2 = reshape(FieldFaceSetPoints2, 3, 3, []);
79FieldFaceSetTwoEdge2 = FieldFaceSetPoints2(:,1:2,:) - repmat( FieldFaceSetPoints2(:,3,:),[ 1 2 1]);
80FieldSrufaceNormalVector2 = cross( FieldFaceSetTwoEdge2(:,1,:), FieldFaceSetTwoEdge2(:,2,:), 1);
81FieldSrufaceNormalVector2 = permute( FieldSrufaceNormalVector2./repmat( sqrt( sum( FieldSrufaceNormalVector2.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget
82
83% Calculate the portion that align with the ray
84SurfNorm1Target2Ray = abs( sum(TargerSrufaceNormalVector1.*Ray1(:,Img1IndexTarget), 1) );
85if CheckOwnRayFlag
86        SurfNorm1Field2Ray = abs( sum(FieldSrufaceNormalVector1.*Ray2(:,Img2IndexField), 1) );
87else
88        SurfNorm1Field2Ray = abs( sum( ( Pair.R*FieldSrufaceNormalVector1 + repmat(Pair.T, 1, size(FieldSrufaceNormalVector1, 2) )).*Ray1(:,Img1IndexTarget), 1) );
89end
90
91% Calculate the portion that align with the ray
92SurfNorm2Target2Ray =  sum( TargerSrufaceNormalVector2.*Ray2(:,Img2IndexTarget), 1) ;
93if CheckOwnRayFlag
94        SurfNorm2Field2Ray = abs( sum( FieldSrufaceNormalVector2.*Ray1(:,Img1IndexField), 1) );
95else
96        SurfNorm2Field2Ray = abs( sum( (Pair.R'*FieldSrufaceNormalVector2 + repmat(-Pair.R'*Pair.T, 1, size(FieldSrufaceNormalVector2, 2) )).*Ray2(:,Img2IndexTarget), 1) );
97end
98
99% ===============================================================================
100
101% Pick out the Plane has a bigger normalized PlanPrameter of the Ray
102if ErareTargetFlag
103        Img1IndexTargetOutliers = abs(SurfNorm1Target2Ray) < abs(SurfNorm1Field2Ray);
104else
105        Img1IndexTargetOutliers = Inf < abs(SurfNorm1Field2Ray);
106end
107Img2IndexFieldOutliers = ~Img1IndexTargetOutliers;
108
109if ErareTargetFlag
110        Img2IndexTargetOutliers = abs(SurfNorm2Target2Ray) < abs(SurfNorm2Field2Ray);
111else
112        Img2IndexTargetOutliers = Inf < abs(SurfNorm2Field2Ray);
113end
114Img1IndexFieldOutliers = ~Img2IndexTargetOutliers;
115
116
117if ErodeRemoveRegionFlag
118   OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri));
119   OriSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0;
120   se = strel('ball',5,5);
121   OriSup = imdilate(OriSup,se);
122   Img1IndexTargetNew = find(OriSup == 0);
123   
124   OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri));
125   OriSup(  Img2IndexField( Img2IndexFieldOutliers)) = 0;
126   se = strel('ball',5,5);
127   OriSup = imdilate(OriSup,se);
128   Img2IndexFieldNew = find(OriSup == 0);
129   
130   OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri));
131   OriSup(  Img2IndexTarget( Img2IndexTargetOutliers)) = 0;
132   se = strel('ball',5,5);
133   OriSup = imdilate(OriSup,se);
134   Img2IndexTargetNew = find(OriSup == 0);
135   
136   OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri));
137   OriSup( Img1IndexField( Img1IndexFieldOutliers)) = 0;
138   se = strel('ball',5,5);
139   OriSup = imdilate(OriSup,se);
140   Img1IndexFieldNew = find(OriSup == 0);
141end   
142
143% Modify the Sup to 0 so that it won't rendered
144tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri;
145tempSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0;
146tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end);
147tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:);
148ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup;
149
150tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri;
151tempSup( Img2IndexField( Img2IndexFieldOutliers)) = 0;
152tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end);
153tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:);
154ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup;
155
156tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri;
157tempSup( Img2IndexTarget( Img2IndexTargetOutliers)) = 0;
158tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end);
159tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:);
160ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup;
161
162tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri;
163tempSup( Img1IndexField( Img1IndexFieldOutliers)) = 0;
164tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end);
165tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:);
166ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup;
167
168
169% assign model1 and model2
170model1 = ImgInfo1.Model;
171model2 = ImgInfo2.Model;
172
173return;
174
Note: See TracBrowser for help on using the repository browser.