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 [CoPEstDepth CoPM1 CoPM2 EstDepHoriStick HoriStickM_i HoriStickM_j EstDepVertStick VertStickM_i VertStickM_j WeiCoP NewSup NewNuSup NewNuSupSize NewSup2Para FixPara VertStickPointInd HoriStickPointInd] ... |
---|
40 | = FreeSupSharpCorner( Sup, Ray, OccluList, WeiV, ShiftStick, StickHori, StickVert, ClosestDist, depthMap, ... |
---|
41 | MultiScaleSupTable, verticalParaInd, graoundParaInd, MultiScaleFlag, Sup2Para); |
---|
42 | |
---|
43 | % This function detect the para needs to be fixed |
---|
44 | % and free the corresponding para near the corner |
---|
45 | % InPut : PlnaePara, Sup, HoriStickPointInd, VertStickPointInd, |
---|
46 | % SepPointMeasureHori, SepPointMeasureVert |
---|
47 | % OutPut: |
---|
48 | % StickVertFreeM StickHoriFreeM Sup2Para FixPara |
---|
49 | |
---|
50 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
51 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
52 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName; |
---|
53 | % initial parameter |
---|
54 | MaxSupNu = max(Sup(:)); |
---|
55 | OriMaxSupNu = MaxSupNu; |
---|
56 | %threSize = prod(size(Sup))*3e-4; |
---|
57 | |
---|
58 | |
---|
59 | % free every sup if not Vert or Ground========================== |
---|
60 | NuSup = setdiff( unique(Sup)',0); |
---|
61 | NuSup = sort(NuSup); |
---|
62 | NuSupFree = setdiff( NuSup, NuSup([ verticalParaInd'; graoundParaInd']) ); |
---|
63 | NewSup = Sup; |
---|
64 | for i = NuSupFree |
---|
65 | i; |
---|
66 | maskfree = Sup == i; |
---|
67 | % end |
---|
68 | % set all free point a new sup index |
---|
69 | NuNewFree = sum(maskfree(:)); |
---|
70 | NewSup(maskfree) = ((MaxSupNu+1):(MaxSupNu+NuNewFree)); |
---|
71 | Sup(maskfree) = 0; |
---|
72 | MaxSupNu = (MaxSupNu+NuNewFree); |
---|
73 | end |
---|
74 | |
---|
75 | % Generate StickVertFreeM StickHoriFreeM Sup2Para FixPara |
---|
76 | NewNuSup = setdiff(unique(NewSup)',0); |
---|
77 | NewNuSup = sort(NewNuSup); |
---|
78 | NewNuSupSize = size(NewNuSup,2); |
---|
79 | NewSup2Para = sparse(1,max(NewSup(:))); |
---|
80 | NewSup2Para(NewNuSup) = 1:NewNuSupSize; |
---|
81 | FixPara = NewNuSup(NewNuSup <= OriMaxSupNu); |
---|
82 | |
---|
83 | BounaryPHori = conv2(Sup,[1 -1],'same') ~=0; |
---|
84 | BounaryPHori(:,end) = 0; |
---|
85 | BounaryPVert = conv2(Sup,[1; -1],'same') ~=0; |
---|
86 | BounaryPVert(end,:) = 0; |
---|
87 | ClosestNList = [ Sup(find(BounaryPHori==1)) Sup(find(BounaryPHori==1)+VertYNuDepth);... |
---|
88 | Sup(find(BounaryPVert==1)) Sup(find(BounaryPVert==1)+1)]; |
---|
89 | ClosestNList = sort(ClosestNList,2); |
---|
90 | ClosestNList = unique(ClosestNList,'rows'); |
---|
91 | ClosestNList(ClosestNList(:,1) == 0,:) = []; |
---|
92 | % find the boundary point that might need to be stick ot each other in Sup at Vert and Hori direction========================================== |
---|
93 | HoriStickM_i = sparse(0,3*NewNuSupSize); |
---|
94 | HoriStickM_j = sparse(0,3*NewNuSupSize); |
---|
95 | HoriStickPointInd = []; |
---|
96 | EstDepHoriStick = []; |
---|
97 | for i = find(BounaryPHori==1)' |
---|
98 | j = i+VertYNuDepth; |
---|
99 | if Sup(i) == 0 || Sup(j) == 0 |
---|
100 | continue; |
---|
101 | end |
---|
102 | % if ~OccluList(sum( ClosestNList == repmat(sort([Sup(i) Sup(j)]), [NuNei 1]),2) == 2) |
---|
103 | % size(OccluList) |
---|
104 | % if ~any(sum( OccluList == repmat(sort([Sup(i) Sup(j)]), [size(OccluList,1) 1]),2) == 2) |
---|
105 | Target(1) = NewSup2Para(Sup(i)); |
---|
106 | Target(2) = NewSup2Para(Sup(j)); |
---|
107 | rayBoundary(:,1) = Ray(:,i); |
---|
108 | rayBoundary(:,2) = Ray(:,i); |
---|
109 | if MultiScaleFlag |
---|
110 | vector = (MultiScaleSupTable(Sup2Para(Sup(i)),2:end) == MultiScaleSupTable(Sup2Para(Sup(j)),2:end)); % MultiScaleSupTable Worked in old index |
---|
111 | expV = exp(-10*(WeiV*vector' + ShiftStick) ); |
---|
112 | betaTemp = StickHori*(0.5+1/(1+expV)); %*(DistStickLengthNormWei.^2)*beta(Target(I)); |
---|
113 | % therr should always be sticking (know don't care about occlusion) |
---|
114 | else |
---|
115 | betaTemp = StickHori; |
---|
116 | end |
---|
117 | temp = sparse(3,NewNuSupSize); |
---|
118 | temp(:,Target(1)) = rayBoundary(:,1); |
---|
119 | HoriStickM_i = [HoriStickM_i; betaTemp*temp(:)']; |
---|
120 | temp = sparse(3,NewNuSupSize); |
---|
121 | temp(:,Target(2)) = rayBoundary(:,2); |
---|
122 | HoriStickM_j = [HoriStickM_j; betaTemp*temp(:)']; |
---|
123 | EstDepHoriStick = [EstDepHoriStick; sqrt(max(depthMap(i),ClosestDist)*max(depthMap(j),ClosestDist))]; |
---|
124 | HoriStickPointInd = [HoriStickPointInd i ]; |
---|
125 | % else |
---|
126 | % disp('Occlu'); |
---|
127 | % end |
---|
128 | end |
---|
129 | VertStickM_i = sparse(0,3*NewNuSupSize); |
---|
130 | VertStickM_j = sparse(0,3*NewNuSupSize); |
---|
131 | VertStickPointInd = []; |
---|
132 | EstDepVertStick = []; |
---|
133 | for i = find(BounaryPVert==1)' |
---|
134 | j = i+1; |
---|
135 | if Sup(i) == 0 || Sup(j) == 0 |
---|
136 | continue; |
---|
137 | end |
---|
138 | % if ~OccluList(sum( ClosestNList == repmat(sort([Sup(i) Sup(j)]), [NuNei 1]),2) == 2) |
---|
139 | % if ~any(sum( OccluList == repmat(sort([Sup(i) Sup(j)]), [size(OccluList,1) 1]),2) == 2) |
---|
140 | Target(1) = NewSup2Para(Sup(i)); |
---|
141 | Target(2) = NewSup2Para(Sup(j)); |
---|
142 | rayBoundary(:,1) = Ray(:,i); |
---|
143 | rayBoundary(:,2) = Ray(:,i); |
---|
144 | if MultiScaleFlag |
---|
145 | vector = (MultiScaleSupTable(Sup2Para(Sup(i)),2:end) == MultiScaleSupTable(Sup2Para(Sup(j)),2:end)); |
---|
146 | expV = exp(-10*(WeiV*vector' + ShiftStick) ); |
---|
147 | betaTemp = StickVert*(0.5+1/(1+expV)); |
---|
148 | % therr should always be sticking (know don't care about occlusion) |
---|
149 | else |
---|
150 | betaTemp = StickVert; |
---|
151 | end |
---|
152 | temp = sparse(3,NewNuSupSize); |
---|
153 | temp(:,Target(1)) = rayBoundary(:,1); |
---|
154 | VertStickM_i = [VertStickM_i; betaTemp*temp(:)']; |
---|
155 | temp = sparse(3,NewNuSupSize); |
---|
156 | temp(:,Target(2)) = rayBoundary(:,2); |
---|
157 | VertStickM_j = [VertStickM_j; betaTemp*temp(:)']; |
---|
158 | EstDepVertStick = [EstDepVertStick; sqrt(max(depthMap(i),ClosestDist)*max(depthMap(j),ClosestDist))]; |
---|
159 | VertStickPointInd = [VertStickPointInd i ]; |
---|
160 | % else |
---|
161 | % disp('Occlu'); |
---|
162 | % end |
---|
163 | end |
---|
164 | |
---|
165 | BounaryPHori = conv2(NewSup,[1 -1],'same') ~=0; |
---|
166 | BounaryPHori(:,end) = 0; |
---|
167 | BounaryPVert = conv2(NewSup,[1; -1],'same') ~=0; |
---|
168 | BounaryPVert(end,:) = 0; |
---|
169 | ClosestNList = [ NewSup(find(BounaryPHori==1)) NewSup(find(BounaryPHori==1)+VertYNuDepth);... |
---|
170 | NewSup(find(BounaryPVert==1)) NewSup(find(BounaryPVert==1)+1)]; |
---|
171 | ClosestNList = sort(ClosestNList,2); |
---|
172 | ClosestNList = unique(ClosestNList,'rows'); |
---|
173 | ClosestNList(ClosestNList(:,1) == 0,:) = []; |
---|
174 | |
---|
175 | % find Coplane need for New added Sup index only |
---|
176 | NuNei = size(ClosestNList,1); |
---|
177 | CoPM1 = sparse(0,3*NewNuSupSize); |
---|
178 | CoPM2 = sparse(0,3*NewNuSupSize); |
---|
179 | CoPEstDepth = sparse(0,0); |
---|
180 | WeiCoP = []; |
---|
181 | for i = 1: NuNei |
---|
182 | % if ~CornerList(i) |
---|
183 | if any( FixPara == ClosestNList(i,1)) && any( FixPara == ClosestNList(i,2)) |
---|
184 | continue; |
---|
185 | end |
---|
186 | mask = NewSup == ClosestNList(i,1); |
---|
187 | SizeMaskAll = sum(mask(:)); |
---|
188 | [y x] = find(mask); |
---|
189 | CenterX = round(median(x)); |
---|
190 | CenterY = round(median(y)); |
---|
191 | y = find(mask(:,CenterX)); |
---|
192 | if ~isempty(y) |
---|
193 | CenterY = round(median(y)); |
---|
194 | end |
---|
195 | temp1 = sparse(1, 3*NewNuSupSize); |
---|
196 | temp2 = sparse(1, 3*NewNuSupSize); |
---|
197 | temp1(:,(NewSup2Para(ClosestNList(i,1))*3-2): NewSup2Para(ClosestNList(i,1))*3) = Ray(:,CenterY,CenterX)'; |
---|
198 | temp2(:,(NewSup2Para(ClosestNList(i,2))*3-2): NewSup2Para(ClosestNList(i,2))*3) = Ray(:,CenterY,CenterX)'; |
---|
199 | wei = 1;%WeiV; |
---|
200 | |
---|
201 | CoPM1 = [CoPM1; temp1*wei]; |
---|
202 | CoPM2 = [CoPM2; temp2*wei]; |
---|
203 | tempWeiCoP = [SizeMaskAll]; |
---|
204 | CoPEstDepth = [CoPEstDepth; max(median(depthMap(mask)),ClosestDist)]; |
---|
205 | |
---|
206 | mask = NewSup == ClosestNList(i,2); |
---|
207 | SizeMaskAll = sum(mask(:)); |
---|
208 | [y x] = find(mask); |
---|
209 | CenterX = round(median(x)); |
---|
210 | CenterY = round(median(y)); |
---|
211 | y = find(mask(:,CenterX)); |
---|
212 | if ~isempty(y) |
---|
213 | CenterY = round(median(y)); |
---|
214 | end |
---|
215 | |
---|
216 | temp1 = sparse(1, 3*NewNuSupSize); |
---|
217 | temp2 = sparse(1, 3*NewNuSupSize); |
---|
218 | temp1(:,(NewSup2Para(ClosestNList(i,1))*3-2): NewSup2Para(ClosestNList(i,1))*3) = Ray(:,CenterY,CenterX)'; |
---|
219 | temp2(:,(NewSup2Para(ClosestNList(i,2))*3-2): NewSup2Para(ClosestNList(i,2))*3) = Ray(:,CenterY,CenterX)'; |
---|
220 | CoPM1 = [CoPM1; temp1*wei]; |
---|
221 | CoPM2 = [CoPM2; temp2*wei]; |
---|
222 | tempWeiCoP = [tempWeiCoP; SizeMaskAll]; |
---|
223 | WeiCoP = [WeiCoP; tempWeiCoP]; |
---|
224 | CoPEstDepth = [CoPEstDepth; max(median(depthMap(mask)),ClosestDist)]; |
---|
225 | % end |
---|
226 | end%========================================================================================================= |
---|
227 | return; |
---|
228 | |
---|
229 | |
---|