source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Debug/OneShot3dEfficient.m @ 37

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

Added original make3d

File size: 10.3 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 OneShot3dEfficient(ImgPath, OutPutFolder,...
40     taskName,...% taskname will append to the imagename and form the outputname
41     ScratchFolder,... % ScratchFolder
42     ParaFolder,... % All Parameter Folder
43     Flag...  % All Flags 1) intermediate storage flag
44     );
45
46if ~isdeployed
47  addpath(genpath('../../LearningCode'));
48 addpath(genpath('../../third_party'));
49 addpath(genpath('../../bin/mex'));
50 end
51
52
53
54% This function is the speed up version of the OneShot3d
55% Improvement Log:
56% 1) speedup segment Mex-file
57% 2) speedup SparseSample3d Mex-file
58% 3) eliminate reading image and filterbank calculation multiple times
59
60% Input:
61% ImgPath -- the path include the file name of the image
62% OutPutFolder -- the path of the output folder
63% ScratchFolder -- intermediante data storage place (used for learning and debug)
64
65% Parameter and Data Setting =========================
66% startTime = tic;
67  tic
68  fprintf('Starting with new optimization...                        ');
69
70  if nargin < 2
71     disp('Eror: At least need two input argument needed');
72     return;
73  elseif nargin < 3
74     taskName = '';
75     Flag = [];
76     ScratchFolder = ['/afs/cs/group/reconstruction3d/scratch/IMStorage' ];
77     ParaFolder = '/afs/cs/group/reconstruction3d/scratch/Para/';
78  elseif nargin < 4
79     Flag = [];
80     ScratchFolder = ['/afs/cs/group/reconstruction3d/scratch/IMStorage' ];
81     ParaFolder = '/afs/cs/group/reconstruction3d/scratch/Para/';
82  elseif nargin < 5
83     Flag = [];
84     ParaFolder = '/afs/cs/group/reconstruction3d/scratch/Para/';
85  elseif nargin < 6
86     Flag = [];
87  end
88
89%       yalmiptest
90
91% parameter setting
92  filename{1} = ImgPath( ( max( strfind( ImgPath, '/'))+1) :end);
93
94  % Function that setup the Default
95  Default = SetupDefault_New(...
96            [ strrep(filename{1}, '.jpg', '') '_' taskName],...
97            ParaFolder,...
98            OutPutFolder,...
99            ScratchFolder,...
100            Flag);
101%  disp([ num2str( toc(startTime) ) ' seconds.']);
102  disp([ num2str( toc ) ' seconds.']);
103
104 
105  % Image loading
106  fprintf('Loading the image...               ');
107  img = imread(ImgPath);
108%  imgCameraParameters = exifread(ImgPath);
109%       if false %Default.Flag.DisplayFlag && (any( strcmp(fieldnames(imgCameraParameters),'FocalLength') ) || ...
110        %                                                 any( strcmp(fieldnames(imgCameraParameters),'FNumber') )      || ...
111        %                                                 any( strcmp(fieldnames(imgCameraParameters),'FocalPlaneXResolution') )        || ...
112        %                                                 any( strcmp(fieldnames(imgCameraParameters),'FocalPlaneYResolution') ) )
113        % FocalPlaneResolutionUnit
114%               disp('This image has known  f  and/or   f/sx ');
115%       end
116%  disp([ num2str( toc(startTime) ) ' seconds.']);
117  disp([ num2str( toc ) ' seconds.']);
118
119 
120% ***************************************************
121
122% Features ===========================================
123
124  % 1) Basic Superpixel generation and Sup clean
125  fprintf('Creating Superpixels...           ');
126  [MedSup, Sup, Default, SupNeighborTable] = gen_Sup_efficient(Default, img);
127%  disp([ num2str( toc(startTime) ) ' seconds.']);
128  disp([ num2str( toc ) ' seconds.']);
129
130
131  % 2) Texture Features and inner multiple Sups generation
132%   load /afs/cs/group/reconstruction3d/scratch/Train400/data/MaskGSky.mat;
133%   load /afs/cs/group/reconstruction3d/scratch/Train400/data/LowResImgIndexSuperpixelSep.mat;
134%   load /afs/cs/group/reconstruction3d/scratch/Train400/data/MedSeg/MediResImgIndexSuperpixelSep1.mat
135%   maskg = maskg{1};
136%   [TextureFeature TextSup]=GenTextureFeature_InnerMulSup(Default, img, Sup{2}, LowResImgIndexSuperpixelSep{1},...
137%                            imresize((MediResImgIndexSuperpixelSep),[Default.TrainVerYSize Default.TrainHoriXSize],'nearest'), 1, maskg);
138% comment compare with old value different only in 1:34 features since
139% superpixel changes
140    fprintf('Creating Features and multiple segmentations... ');
141    [TextureFeature TextSup]=GenTextureFeature_InnerMulSup(Default, img, Sup{2}, Sup{1},...
142                           imresize((MedSup),[Default.TrainVerYSize Default.TrainHoriXSize],'nearest'), 1);%, maskg);
143%  disp([ num2str( toc(startTime) ) ' seconds.']);
144  disp([ num2str( toc ) ' seconds.']);
145
146  % 3) Superpixel Features generation
147%    [FeatureSupOld, NeighborListOld] = f_sup_old(Default,
148%    LowResImgIndexSuperpixelSep{1}, MediResImgIndexSuperpixelSep); % old
149%    data comparison
150  % new code using prctile replace cause mean diff of 1e-4
151  fprintf('Calculating superpixel-shape features...       ');
152  [FeatureSup] = f_sup_old(Default, Sup{1}, MedSup, SupNeighborTable);
153 % disp([ num2str( toc(startTime) ) ' seconds.']);
154  disp([ num2str( toc ) ' seconds.']);
155
156  if Default.Flag.IntermediateStorage
157     save([ ScratchFolder '/' strrep( filename{1},'.jpg','') '_IM.mat' ],'FeatureSup','TextureFeature','Sup','TextSup');
158  end
159
160  %************************************SID
161%  if Default.Flag.FeatureStorage
162%       name = [strrep(filename{1}, '.jpg', '') '_' taskName];
163%       save([ScratchFolder '/' name '.mat'],'TextureFeature','FeatureSup');
164%  end
165
166  if Default.Flag.FeaturesOnly
167     return;
168  end
169  % at the end with 36130018 bytes in memory
170%     Name                 Size                           Bytes  Class
171%   DefaTextureFeatureult              1x1                             5596  struct array
172%   DepthPara            0x0                                0  char array
173%   FeaPara              1x54                             108  char array
174%   FeatureSup          13x808                          84032  double array
175%   GroundPara           0x0                                0  char array
176%   ImgPath              1x78                             156  char array
177%   filename          1                              66  cell array
178%   MedSup            1200x900                        8640000  double array
179%   NeighborList      5134x2                            82144  double array
180%   OutPutFolder         0x0                                0  char array
181%   SFeaPara             1x54                             108  char array
182%   ScratchFlag          1x1                                8  double array
183%   ScratchFolder        0x0                                0  char array
184%   SkyPara              0x0                                0  char array
185%   Sup                  1x3                           402888  cell array
186%   TextSup              6x2                          1611552  cell array
187%   TextureFeature       1x1                         13688896  struct array
188%   VarPara              0x0                                0  char array
189%   img               2272x1704x3                    11614464  uint8 array
190%   taskName             0x0                                0  char array
191
192% ***************************************************
193
194% Inference ==========================================
195 
196  fprintf('Preparation for the Inference...             ');
197  % 1) Generate Ground and Sky mask
198  [ maskg, maskSky] = gen_predicted_GS_efficient(Default, TextureFeature.Abs, FeatureSup);
199
200  % 2) Clean Sup{1} (1st Scale) according to the sky mask
201  [Sup{1}, SupOri, SupNeighborTable]=CleanedSupNew(Default,Sup{1},maskSky, SupNeighborTable);
202
203  % 3) Generate predicted (depth:1 Variance:2 ) setup as a row verctor
204  [Predicted]=gen_predicted(Default, TextureFeature.Abs, FeatureSup, [1 2]);
205
206  if Default.Flag.BeforeInferenceStorage
207     save([ ScratchFolder '/' strrep( filename{1},'.jpg','') '_BInf.mat' ], 'Sup', 'SupOri', 'MedSup', 'Predicted', 'maskg', 'maskSky');
208  end
209  if Default.Flag.NonInference
210     return;
211  end
212%  disp([ num2str( toc(startTime) ) ' seconds.']);
213   disp([ num2str( toc ) ' seconds.']);
214 
215  fprintf('Starting Inference... ');
216  % 4) Plane Parameter MRF
217  RunCompleteMRF_efficient( Default, img, Predicted, MedSup, Sup, SupOri, TextSup, SupNeighborTable, ...
218                            reshape( FeatureSup( TextureFeature.Abs(:,1)), Default.VertYNuDepth, []), ...
219                            maskSky, maskg); 
220%  disp(['Finished Inference at:         ' num2str( toc(startTime) ) ' seconds.']);
221   disp(['Finished Inference at:         ' num2str( toc ) ' seconds.']);
222 
223  % 5) output data
224  fprintf('Writing superpixels and image...  ');
225  save([ Default.OutPutFolder Default.filename{1} '.mat'],'MedSup');
226
227  % 6) Image copy to OutPutFolder
228  %system(['cp ' ImgPath ' ' OutPutFolder Default.filename{1} '.jpg']);
229  copyfile(ImgPath, [OutPutFolder Default.filename{1} '.jpg'],'f');
230%  disp([ num2str( toc(startTime) ) ' seconds.']);
231%  disp(['Done.        Total time taken = ' num2str( toc(startTime) ) ' seconds.'] );
232  disp([ 'Done.        Total time taken = ' num2str( toc ) ' seconds.']);
233
234
235% ***************************************************
236
237return;
Note: See TracBrowser for help on using the repository browser.