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 []=gen_predictedM_new(learningType,SkyExclude,logScale,LearnNear,... |
---|
40 | LearnAlg,LearnDate,AbsFeaType,AbsFeaDate,HistFeaType,HistFeaDate,... |
---|
41 | FeaBatchNumber,WeiBatchNumber); |
---|
42 | %learningType,logScale,SkyExclude,LearnAlg,AbsFeaType,AbsFeaDate,WeiBatchNumber,logScale,SkyExclude,LearnNear) |
---|
43 | % this function generate the learned depth |
---|
44 | |
---|
45 | % define global variable |
---|
46 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
47 | ImgFolder TrainSet VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
48 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize; |
---|
49 | |
---|
50 | % load estimated sky |
---|
51 | load([ScratchDataFolder '/data/MaskGSky.mat']); % maskg is the estimated ground maskSky is the estimated sky |
---|
52 | |
---|
53 | % load superpixel Feadture |
---|
54 | load([ScratchDataFolder '/data/FeatureSuperpixel.mat']); % load the feature relate to position and shape of superpixel |
---|
55 | |
---|
56 | % load all the thi in different rows |
---|
57 | thit = []; |
---|
58 | thit_base = []; |
---|
59 | for i = 1:ceil(NuRow_default/WeiBatchSize) % only consider two learning type 'Abs' = Depth 'Fractional' = FractionalRegDepth |
---|
60 | if strcmp(learningType,'Fractional') |
---|
61 | load([ScratchDataFolder '/../learned_parameter/FractionalDepth_' TrainSet '_' LearnAlg ... |
---|
62 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
63 | '_Near' num2str(LearnNear) '_WeiBatNu' num2str(i) ... |
---|
64 | '_' AbsFeaType '_AbsFeaDate' '' '_LearnDate' LearnDate '.mat']); |
---|
65 | % '_' AbsFeaType '_AbsFeaDate' AbsFeaDate '_LearnDate' LearnDate '.mat']); |
---|
66 | else |
---|
67 | load([ScratchDataFolder '/../learned_parameter/Depth_' TrainSet '_' LearnAlg ... |
---|
68 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
69 | '_Near' num2str(LearnNear) '_WeiBatNu' num2str(i) ... |
---|
70 | '_' AbsFeaType '_AbsFeaDate' '' '_LearnDate' LearnDate '.mat']); |
---|
71 | % '_' AbsFeaType '_AbsFeaDate' AbsFeaDate '_LearnDate' LearnDate '.mat']); |
---|
72 | end |
---|
73 | thit = [thit thi]; |
---|
74 | thit_base = [thit_base thi_base]; |
---|
75 | end |
---|
76 | thit = cell2mat(thit); |
---|
77 | thit_base = cell2mat(thit_base); |
---|
78 | |
---|
79 | % mkdir to store the depth in scratch space |
---|
80 | system(['mkdir ' ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
81 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
82 | '_Near' num2str(LearnNear)]); |
---|
83 | system(['mkdir ' ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
84 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
85 | '_Near' num2str(LearnNear) '_baseline']); |
---|
86 | system(['mkdir ' ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
87 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
88 | '_Near' num2str(LearnNear) '_baseline2']); |
---|
89 | %if strcmp(learningType,'Fractional') |
---|
90 | % system(['mkdir ' ScratchDataFolder '/_LearnFDLinearNonSky_']); |
---|
91 | % disp('Fractional') |
---|
92 | %else |
---|
93 | % if logScale==1 |
---|
94 | % if SkyExclude == 1 |
---|
95 | % system(['mkdir ' ScratchDataFolder '/_LearnDLogScaleNonskySep_' learningType]); |
---|
96 | % else |
---|
97 | % system(['mkdir ' ScratchDataFolder '/_LearnDLogScale_' learningType]); |
---|
98 | % end |
---|
99 | % else |
---|
100 | % if SkyExclude ==1 |
---|
101 | % system(['mkdir ' ScratchDataFolder '/_LearnDNonsky_' learningType]); |
---|
102 | % else |
---|
103 | % system(['mkdir ' ScratchDataFolder '/_LearnD_' learningType]); |
---|
104 | % end |
---|
105 | % end |
---|
106 | %end |
---|
107 | |
---|
108 | NuPics = size(filename,2); % number of pictures |
---|
109 | NuFeaBatch = ceil(NuPics/batchSize); |
---|
110 | for j =1:NuFeaBatch |
---|
111 | % load([ScratchDataFolder '/data/feature_sqrt_H4_ray' int2str(j) '.mat']); % 'f' |
---|
112 | load([ScratchDataFolder '/data/feature_Abs_Whole' int2str(j) '_' AbsFeaDate '.mat']); |
---|
113 | % load([ScratchDataFolder '/data/oldFea/feature_Abs_Whole' int2str(j) '_' AbsFeaDate '.mat']); |
---|
114 | for k = 1:size(f,2)%batchSize |
---|
115 | |
---|
116 | %================ |
---|
117 | % load picsinfo just for the horizontal value |
---|
118 | (j-1)*batchSize+k % pics Number |
---|
119 | |
---|
120 | PicsinfoName = strrep(filename{(j-1)*batchSize+k},'img','picsinfo'); |
---|
121 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
122 | if size(temp,1) == 0 |
---|
123 | a = a_default; |
---|
124 | b = b_default; |
---|
125 | Ox = Ox_default; |
---|
126 | Oy = Oy_default; |
---|
127 | Horizon = Horizon_default; |
---|
128 | else |
---|
129 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
130 | end |
---|
131 | |
---|
132 | % prepare the thiMatrix |
---|
133 | NuRow = NuRow_default; |
---|
134 | for i = 1:NuRow; |
---|
135 | RowskyBottom = ceil(NuRow/2); |
---|
136 | PatchSkyBottom = ceil(VertYNuDepth*(1-Horizon)); |
---|
137 | if i <= RowskyBottom |
---|
138 | PatchRowRatio = PatchSkyBottom/RowskyBottom; |
---|
139 | RowTop(i) = ceil((i-1)*PatchRowRatio+1); |
---|
140 | RowBottom(i) = ceil(i*PatchRowRatio); |
---|
141 | else |
---|
142 | PatchRowRatio = (VertYNuDepth-PatchSkyBottom)/(NuRow-RowskyBottom); |
---|
143 | RowTop(i) = ceil((i-RowskyBottom-1)*PatchRowRatio+1)+PatchSkyBottom; |
---|
144 | RowBottom(i) = ceil((i-RowskyBottom)*PatchRowRatio)+PatchSkyBottom; |
---|
145 | end |
---|
146 | end |
---|
147 | RowNumber = RowBottom'-RowTop'+1; |
---|
148 | thiRow = []; |
---|
149 | thi_baseRow = []; |
---|
150 | for i = 1:NuRow; |
---|
151 | thiRow = [ thiRow thit(:,i*ones(RowNumber(i),1))]; |
---|
152 | thi_baseRow = [ thi_baseRow thit_base(:,i*ones(RowNumber(i),1))]; |
---|
153 | thi_baseRow2 = thi_baseRow; |
---|
154 | thi_baseRow2(:) = mean(thi_baseRow2); |
---|
155 | end |
---|
156 | %================ |
---|
157 | % FeaVectorPics = genFeaVector(f{k},FeatureSuperpixel{(j-1)*batchSize+k},... |
---|
158 | % 1,VertYNuDepth,1,HoriXNuDepth,(j-1)*batchSize+k); |
---|
159 | FeaVectorPics = genFeaVector(f{k},FeatureSuperpixel{(j-1)*batchSize+k},... |
---|
160 | [1:VertYNuDepth],[1:HoriXNuDepth],(j-1)*batchSize+k,0); |
---|
161 | if logScale ==1 |
---|
162 | depthMap = exp(reshape(sum([ones(size(FeaVectorPics,2),1) FeaVectorPics'].*... |
---|
163 | repmat(thiRow',[HoriXNuDepth 1]),2),VertYNuDepth,[])); |
---|
164 | depthMap_base = exp(reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
165 | repmat(thi_baseRow',[HoriXNuDepth 1]),2),VertYNuDepth,[])); |
---|
166 | depthMap_base2 = exp(reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
167 | repmat(thi_baseRow2',[HoriXNuDepth 1]),2),VertYNuDepth,[])); |
---|
168 | else |
---|
169 | size(thiRow) |
---|
170 | size(FeaVectorPics) |
---|
171 | depthMap = reshape(sum([ones(size(FeaVectorPics,2),1) FeaVectorPics'].*... |
---|
172 | repmat(thiRow',[HoriXNuDepth 1]),2),VertYNuDepth,[]); |
---|
173 | depthMap_base = reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
174 | repmat(thi_baseRow',[HoriXNuDepth 1]),2),VertYNuDepth,[]); |
---|
175 | depthMap_base2 = reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
176 | repmat(thi_baseRow2',[HoriXNuDepth 1]),2),VertYNuDepth,[]); |
---|
177 | end |
---|
178 | % disp('Differnet from base to whole') |
---|
179 | % mean(mean(depthMap - depthMap_base)) |
---|
180 | %=====================SkyExclude===================== |
---|
181 | if SkyExclude ==1 |
---|
182 | depthMap(maskSky{(j-1)*batchSize+k}) = max(max(depthMap))+30; |
---|
183 | depthMap_base(maskSky{(j-1)*batchSize+k}) = max(max(depthMap_base))+30; |
---|
184 | depthMap_base2(maskSky{(j-1)*batchSize+k}) = max(max(depthMap_base2))+30; |
---|
185 | end |
---|
186 | %==================================================== |
---|
187 | depthfile = strrep(filename{(j-1)*batchSize+k},'img','depth_learned'); % |
---|
188 | % save([ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
189 | % '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
190 | % '_Near' num2str(LearnNear) '_OriRes/' depthfile '.mat'],'depthMap'); |
---|
191 | % save([ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
192 | % '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
193 | % '_Near' num2str(LearnNear) '_baseline_OriRes/' depthfile '.mat'],'depthMap_base'); |
---|
194 | save([ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
195 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
196 | '_Near' num2str(LearnNear) '/' depthfile '.mat'],'depthMap'); |
---|
197 | save([ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
198 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
199 | '_Near' num2str(LearnNear) '_baseline/' depthfile '.mat'],'depthMap_base'); |
---|
200 | save([ScratchDataFolder '/' learningType '_' LearnAlg ... |
---|
201 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
202 | '_Near' num2str(LearnNear) '_baseline2/' depthfile '.mat'],'depthMap_base2'); |
---|
203 | % if strcmp(learningType,'Fractional') |
---|
204 | % save([ScratchDataFolder '/_LearnFDLinearNonSky_/' depthfile '.mat'], 'depthMap'); |
---|
205 | % else |
---|
206 | % if logScale == 1 |
---|
207 | % if SkyExclude == 1 |
---|
208 | % save([ScratchDataFolder '/_LearnDLogScaleNonskySep_' learningType '/' depthfile '.mat'],'depthMap'); |
---|
209 | % else |
---|
210 | % save([ScratchDataFolder '/_LearnDLogScale_' learningType '/' depthfile '.mat'],'depthMap'); |
---|
211 | % end |
---|
212 | % else |
---|
213 | % if SkyExclude == 1 |
---|
214 | % save([ScratchDataFolder '/_nLearnDNonsky_' learningType '/' depthfile '.mat'],'depthMap'); |
---|
215 | % else |
---|
216 | % save([ScratchDataFolder '/_LearnD_' learningType '/' depthfile '.mat'],'depthMap'); |
---|
217 | % end |
---|
218 | % end |
---|
219 | % end |
---|
220 | end |
---|
221 | end |
---|