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