source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Inference/OldVersion/PredictPlaneOrientEst.m @ 37

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

Added original make3d

File size: 21.8 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 []=PredictPlane(DepthDirectory,logScale,SkyExclude)
40%this function generate the predicted plane
41
42
43% define global variable
44global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory...
45    ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default...
46    Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize;
47
48% load data
49load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % load LowResImgIndexSuperpixelSep
50load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); % load DiffLowResImgIndexSuperpixelSep(medi$large)
51load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSep.mat']); % load TextLowResImgIndexSuperpixelSep using Textrea
52load([ScratchDataFolder '/data/MaskGSky.mat']); % load maskg maskSky from CMU's output
53%load([ScratchDataFolder '/data/maskO.mat']);
54% load useful features
55load([ScratchDataFolder '/data/FeatureSuperpixel.mat']); % load the feature relate to position and shape of superpixe
56
57% prepare to store the predictedM
58system(['mkdir ' ScratchDataFolder '/_predicted_' DepthDirectory]);
59
60% set parameter
61ZTiltFactor = 1; % both can be estimated after group fit that estimate the Norm_floor
62YTiltFactor = 1;
63% initial parameter
64NuPics = size(filename,2);
65for i = 1 : NuPics
66        i
67        % load picsinfo just for the horizontal value
68        PicsinfoName = strrep(filename{i},'img','picsinfo');
69        temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
70        if size(temp,1) == 0
71            a = a_default;
72            b = b_default;
73            Ox = Ox_default;
74            Oy = Oy_default;
75            Horizon = Horizon_default;
76        else   
77            eload([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
78        end
79   
80        % load useful feature
81        BatchNumber = ceil(i/batchSize);
82        PicsNumber = mod(i,batchSize);
83        if PicsNumber ==0
84         PicsNumber = 10;
85        end
86%         load([ScratchDataFolder '/data/feature_sqrt_H4_ray' int2str(BatchNumber) '.mat']); % 'f'
87%         f = f{PicsNumber};
88%         f = f(:,1);
89%         fsup = FeatureSuperpixel{i};
90%         f = (fsup(1,f))';
91       
92        % load depthMap
93        depthfile = strrep(filename{i},'img','depth_learned'); % the depth filename
94        if logScale == 1
95            if SkyExclude ==1
96                load([ScratchDataFolder '/_LearnDLogScaleNonsky_' DepthDirectory '/' depthfile '.mat']);
97            else
98                load([ScratchDataFolder '/_LearnDLogScale_' DepthDirectory '/' depthfile '.mat']);
99            end
100        else
101            if SkyExclude ==1
102                load([ScratchDataFolder '/_LearnD_' DepthDirectory '/' depthfile '.mat']);
103            else
104                load([ScratchDataFolder '/_LearnD_' DepthDirectory '/' depthfile '.mat']);
105            end
106        end
107           
108        LearnedDepth = depthMap; clear depthMap;
109       
110        % initialize parameter
111        NuPatch = VertYNuDepth*HoriXNuDepth;
112       
113        % generate straight line for straight line prior
114        Img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg'],'jpg');
115        if  prod(size(Img))> SegVertYSize*SegHoriXSize*3
116            Img = imresize(Img,[SegVertYSize SegHoriXSize],'nearest');
117        end
118        [ImgYSize ImgXSize dummy] = size(Img);
119        [lineSegList] = edgeSegDetection(Img);
120        NuSeg = size(lineSegList,1);
121        % order the line segment by their length
122        lineSegList = lineSegList./repmat([ImgXSize ImgYSize ImgXSize ImgYSize],NuSeg,1)...
123                      .*repmat([HoriXNuDepth VertYNuDepth HoriXNuDepth VertYNuDepth],NuSeg,1);
124
125        % take out the vertical edge so that we may combine it with 1stSmooth in Y direction
126        VertLineSegList = lineSegList(abs(round(lineSegList(:,1))-round(lineSegList(:,3))) <=0 & ...
127                                      abs(round(lineSegList(:,2))-round(lineSegList(:,4))) > 0 ,:);
128        VertLineSegList = round(VertLineSegList);
129        NuVertSeg = size(VertLineSegList,1);
130        VertLineMask = zeros(VertYNuDepth, HoriXNuDepth);
131        for k = 1:NuVertSeg
132            if VertLineSegList(k,2) < VertLineSegList(k,4)
133               VertLineMask(max(VertLineSegList(k,2),1):min((VertLineSegList(k,4)-1),VertYNuDepth),...
134                            min(max(VertLineSegList(k,1),1),HoriXNuDepth)) = 1;
135            else
136               VertLineMask(max(VertLineSegList(k,4),1):min((VertLineSegList(k,2)-1),VertYNuDepth),...
137                            min(max(VertLineSegList(k,1),1),HoriXNuDepth)) = 1;
138            end
139        end
140         
141        [StraightLinePriorSelectMatrix RayPorjectImgMapY LineIndex newd] = StraightLinePrior(lineSegList,LearnedDepth,a,b,Ox,Oy);
142%         
143        % generate ray porjection position in the image plane
144        RayPorjectImgMapY = ((VertYNuDepth+1-RayPorjectImgMapY)-0.5)/VertYNuDepth - Oy;
145        RayPorjectImgMapX = repmat(((1:HoriXNuDepth)-0.5)/HoriXNuDepth - Ox,[VertYNuDepth 1]);
146        % generate specific ray for whole pics
147        RayCenter = RayImPosition(RayPorjectImgMapY,RayPorjectImgMapX,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
148        Rx = RayCenter(:,:,1);
149        Rx = Rx(:);
150        Ry = RayCenter(:,:,2);
151        Ry = Ry(:);
152        Rz = RayCenter(:,:,3);
153        Rz = Rz(:);
154
155%=====================================================       
156        % MRF reshape the 3d cloud
157
158        NuSupType = size(LowResImgIndexSuperpixelSep,2)+size(DiffLowResImgIndexSuperpixelSep,2)...
159                   +size(TextLowResImgIndexSuperpixelSep,2)*size(TextLowResImgIndexSuperpixelSep,3);
160
161        for j = 1:NuSupType  % total 21 seg : 3 RGB 6*3= 18 texture filters
162
163            % pick the specific segmentation
164            if j==1
165                sup = LowResImgIndexSuperpixelSep{i,1};
166            elseif j<=3
167                sup = DiffLowResImgIndexSuperpixelSep{i,j-1};
168            else
169                Subm = mod((j-3),6);
170                if Subm==0
171                   Subm=6;
172                end
173                sup = TextLowResImgIndexSuperpixelSep{i,Subm,ceil((j-3)/6)};
174            end
175
176            % Exclude the sky first
177            sup(maskSky{i} == 1) = 0;
178            [SelectY{j} SelecrX{j} BM{j} Ns{j} MediaM{j} MeanM{j}] = OrientEst(sup, RayCenter);
179        end
180 
181        % set weight for different segmentation
182        small=10; med=5; large=1;
183        temp =[small; med; large; small*ones(6,1); med*ones(6,1) ;large*ones(6,1)]
184       
185        % set weight for the VertLineSeg Ground and VertialWalls
186        WeiLinSegVertWall = 112;
187        WeiLinSegVertGround = 112;
188
189        % set weight for the straight line prior
190        WeiStraightLine = 1120
191
192        % generate the smooth matrix
193        M2ndSmoothY = spdiags([ones(NuPatch,1) -2*ones(NuPatch,1) ones(NuPatch,1)],[-1 0 1],NuPatch,NuPatch);
194        M2ndSmoothX = spdiags([ones(NuPatch,1) -2*ones(NuPatch,1) ones(NuPatch,1)],...
195                              [-VertYNuDepth 0 VertYNuDepth],NuPatch,NuPatch);
196        M1stSmoothY = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 1],NuPatch,NuPatch);
197        M1stSmoothX = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 VertYNuDepth],NuPatch,NuPatch);
198
199        % generate beta
200%        beta2ndSmoothGX = Wei2ndSmoothGX'*ones(21,1) * logisticResponse(Wei2ndSmoothGX'*SecXG / (Wei2ndSmoothGX'*ones(21,1)) );
201        beta2ndSmoothGX = Wei2ndSmoothGX'*SecXG;
202%MIN: TO DO
203%MIN: TO DO
204        beta2ndSmoothGY = Wei2ndSmoothGY'*SecYG;
205%        beta2ndSmoothGY = Wei2ndSmoothGY'*ones(21,1) * logisticResponse(Wei2ndSmoothGY'*SecYG / (Wei2ndSmoothGY'*ones(21,1)) );
206        beta2ndSmoothGY = Wei2ndSmoothGY'*SecYG;
207%        beta2ndSmoothVX = Wei2ndSmoothVX'*ones(21,1) * logisticResponse(Wei2ndSmoothVX'*SecXV / (Wei2ndSmoothVX'*ones(21,1)) );
208        beta2ndSmoothVX = Wei2ndSmoothVX'*SecXV;
209%        beta2ndSmoothVY = Wei2ndSmoothVY'*ones(21,1) * logisticResponse(Wei2ndSmoothVY'*SecYV / (Wei2ndSmoothVY'*ones(21,1)) );
210        beta2ndSmoothVY = Wei2ndSmoothVY'*SecYV;
211%        beta2ndSmoothSX = Wei2ndSmoothSX'*ones(21,1) * logisticResponse(Wei2ndSmoothSX'*SecXS / (Wei2ndSmoothSX'*ones(21,1)) );
212%        beta2ndSmoothSY = Wei2ndSmoothSY'*ones(21,1) * logisticResponse(Wei2ndSmoothSY'*SecYS / (Wei2ndSmoothSY'*ones(21,1)) );
213
214%        beta1stSmoothGY = Wei1stSmoothGY'*ones(21,1)*logisticResponse(Wei1stSmoothGY'*FirstYG/(Wei1stSmoothGY'*ones(21,1)) );
215        beta1stSmoothGY = Wei2ndSmoothGY'*FirstYG;
216%        beta1stSmoothVY = Wei1stSmoothVY'*ones(21,1)*logisticResponse(Wei1stSmoothVY'*FirstYV/(Wei1stSmoothVY'*ones(21,1)) );
217        beta1stSmoothVY = Wei2ndSmoothVY'*FirstYV;
218%        beta1stSmoothSY = Wei1stSmoothSY'*ones(21,1)*logisticResponse(Wei1stSmoothSY'*FirstYS/(Wei1stSmoothSY'*ones(21,1)) );
219%        beta1stSmoothGX = Wei1stSmoothGX'*ones(21,1)*logisticResponse(Wei1stSmoothGX'*FirstXG/(Wei1stSmoothGX'*ones(21,1)) );
220        beta1stSmoothGX = Wei2ndSmoothGX'*FirstXG;
221%        beta1stSmoothVX = Wei1stSmoothVX'*ones(21,1)*logisticResponse(Wei1stSmoothVX'*FirstXV/(Wei1stSmoothVX'*ones(21,1)) );
222        beta1stSmoothVX = Wei2ndSmoothVX'*FirstXV;
223%        beta1stSmoothSX = Wei1stSmoothSX'*ones(21,1)*logisticResponse(Wei1stSmoothSX'*FirstXS/(Wei1stSmoothSX'*ones(21,1)) );
224       
225        Beta1stSmoothLineGY = VertLineMask.*(maskEstGVS==1)*WeiLinSegVertGround;
226        Beta1stSmoothLineGY = (Beta1stSmoothLineGY(:))';
227        Beta1stSmoothLineVWY = VertLineMask.*(maskEstGVS==2)*WeiLinSegVertWall;
228        Beta1stSmoothLineVWY = (Beta1stSmoothLineVWY(:))';
229       
230        % generate Q
231%        Q2ndXx = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'...
232%                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch);
233%        Q2ndXy = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'...
234%                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch);
235%        Q2ndXz = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'...
236%                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); 
237%        Q2ndYx = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'...
238%                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch);   
239%        Q2ndYy = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'...
240%                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch);
241%        Q2ndYz = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'...
242%                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch);
243 
244        Q2ndXx = spdiags((beta2ndSmoothGX+beta2ndSmoothVX)'...
245                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch);
246        Q2ndXy = spdiags((beta2ndSmoothGX+beta2ndSmoothVX)'...
247                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch);
248        %Q2ndXz = spdiags((beta2ndSmoothGX+beta2ndSmoothVX)'...
249        %         ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); 
250        Q2ndXz = spdiags((beta2ndSmoothVX)'...
251                 ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); 
252        Q2ndYx = spdiags((beta2ndSmoothGY+beta2ndSmoothVY)'...
253                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch);   
254        Q2ndYy = spdiags((beta2ndSmoothGY+beta2ndSmoothVY)'...
255                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch);
256        %Q2ndYz = spdiags((beta2ndSmoothGY+beta2ndSmoothVY)'...
257        %         ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch);
258        Q2ndYz = spdiags((beta2ndSmoothVY)'...
259                 ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch);
260
261        Q2ndLinex = WeiStraightLine*StraightLinePriorSelectMatrix*spdiags(Rx,0,NuPatch,NuPatch);
262        Q2ndLiney = WeiStraightLine*StraightLinePriorSelectMatrix*spdiags(Ry,0,NuPatch,NuPatch);
263        Q2ndLinez = WeiStraightLine*StraightLinePriorSelectMatrix*spdiags(Rz,0,NuPatch,NuPatch);
264         
265%        Q1stYz = spdiags((beta1stSmoothVY+beta1stSmoothSY+Beta1stSmoothLineVWY)'...
266%                 ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
267        %Q1stYz = spdiags((Beta1stSmoothLineVWY)'...
268        %         ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
269%        Q1stYy = spdiags((beta1stSmoothGY+Beta1stSmoothLineGY)'...
270%                 ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Ry*YTiltFactor,0,NuPatch,NuPatch);
271%        Q1stXz = spdiags((beta1stSmoothGX+beta1stSmoothVX+beta1stSmoothSX)'...
272%                 ,0,NuPatch,NuPatch)*M1stSmoothX*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
273
274
275        %Q1stYz = spdiags((beta1stSmoothVY+Beta1stSmoothLineVWY)'...
276        %         ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
277        Q1stYz = spdiags((beta1stSmoothVY+Beta1stSmoothLineVWY)'...
278                 ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
279        Q1stYy = spdiags((beta1stSmoothGY+Beta1stSmoothLineGY)'...
280                 ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Ry*YTiltFactor,0,NuPatch,NuPatch);
281        Q1stXz = spdiags((beta1stSmoothGX+beta1stSmoothVX)'...
282                 ,0,NuPatch,NuPatch)*M1stSmoothX*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch);
283% ============================START MRF OPTMIZATIOM=========================================================
284         %=================
285         % generate mask for depth difference
286         YDiff = repmat(logical([ones(VertYNuDepth-1,1); 0]),1,HoriXNuDepth);
287         XDiff = repmat(([ones(1,HoriXNuDepth-1) 0]),VertYNuDepth,1);
288         DMatrixY = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 1],NuPatch,NuPatch);
289         %DMatrixY = DMatrixY(~maskO,:);
290         DMatrixX = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 VertYNuDepth],NuPatch,NuPatch);
291         %=================
292         tic;
293% lineprog ===========================================
294%         B = [DMatrixY;spdiags(maskO(:),[0],NuPatch,NuPatch)];
295%         Q = [Q2ndXz;Q2ndYz];
296%         A = [B -speye(size(B,1)) sparse(size(B,1),size(Q,1));...
297%             -B -speye(size(B,1)) sparse(size(B,1),size(Q,1));...
298%              Q sparse(size(Q,1),size(B,1)) -speye(size(Q,1));...
299%             -Q sparse(size(Q,1),size(B,1)) -speye(size(Q,1));...
300%             -speye(NuPatch) sparse(NuPatch,size(B,1)+size(Q,1))];
301%         bb = [B*LearnedDepth(:); - B*LearnedDepth(:);...
302%               sparse(size(Q,1)*2,1); -5*ones(NuPatch,1)];
303%         f = [sparse(NuPatch,1); ones(size(B,1)+size(Q,1),1)];
304%         x = linprog(f,A,bb);
305%=====================================================
306
307% quadprog ===========================================
308% only 2nd order smooth use L1 norm
309        Q1size = size([Q1stYy; Q1stYz;Q1stXz],1)
310        SLsize = size(Q2ndLinez,1)
311        Bsize = size([Q2ndXz;Q2ndYz],1)
312%       E = [Q1stYy ;Q1stYz; Q1stXz;...
313%              spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch);...
314%              Q2ndLinez];
315%        e = [sparse(Q1size,1); -LearnedDepth(:); sparse(SLsize,1)];
316%        B = [Q2ndXz ; Q2ndYz];
317%       H = 2*[[Q1stYy;Q1stYz; Q1stXz;...
318%              spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch);Q2ndLinez]'*...
319%             [Q1stYy;Q1stYz; Q1stXz;...
320%              spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch);Q2ndLinez] sparse(NuPatch,Bsize*3);...
321%              sparse(Bsize*3,NuPatch+Bsize*3)];
322%        f =[2*[sparse(Q1size,1); -LearnedDepth(:); sparse(SLsize,1)]'*...
323%            [Q1stYy;Q1stYz; Q1stXz...
324%             spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch); Q2ndLinez] ones(1,Bsize) sparse(1,Bsize*2)]';
325%        Aeq = [[Q2ndXz ; Q2ndYz] -spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
326%               spdiags(ones(Bsize,1),[0],Bsize,Bsize) sparse(Bsize,Bsize);...
327%              [Q2ndXz ; Q2ndYz] spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
328%               sparse(Bsize,Bsize) spdiags(ones(Bsize,1),[0],Bsize,Bsize)];
329%        beq = sparse(Bsize*2,1);
330%        lb = [5*ones(NuPatch,1);sparse(Bsize*2,1);...
331%              -2*max(LearnedDepth(:))*ones(Bsize,1)];
332%        ub = [max(LearnedDepth(:))*ones(NuPatch,1);...
333%              2*max(LearnedDepth(:))*ones(Bsize*2,1); sparse(Bsize,1)];
334%        options = optimset('LargeScale', 'on', 'Display', 'off');
335%        x = quadprog(H,f,[],[],Aeq,beq,lb,ub,[],options);
336%        predictedM = [spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch)...
337%                      sparse(NuPatch,Bsize*3)]*x;
338%        A = [sparse(Bsize*2,NuPatch+Bsize)...
339%             spdiags([-ones(Bsize,1);ones(Bsize,1)],[0],Bsize*2,Bsize*2)];
340%        b =sparse(Bsize*2,1);
341%=====================================================
342%         predictedM = spdiags([ones(1,NuPatch) sparse(1,size(B,1)+size(Q,1))]',0,NuPatch...
343%                             ,NuPatch+size(B,1)+size(Q,1))*x;
344%        predictedM = (LearnedDepth(:));
345
346
347             %[[Q2ndYz] -spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
348             %   spdiags(ones(Bsize,1),[0],Bsize,Bsize) sparse(Bsize,Bsize);...
349             %  [Q2ndYz] spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
350             %   sparse(Bsize,Bsize) spdiags(ones(Bsize,1),[0],Bsize,Bsize)]*[predictedM; kt; ga; al] == 0;
351             
352%             [Q2ndXz; Q2ndYz]*predictedM <=kt;
353%             [Q2ndXz; Q2ndYz]*predictedM >= -kt;
354%             predictedM>=5;
355              %ga>=0;
356              %al<=0;
357%         cvx_end   
358%         toc;
359
360% post prosessing on straight line
361
362% second optimization
363       
364        Date =date;
365%        predictedM =reshape(predictedM,VertYNuDepth,[]);
366         % quadprog Start
367%         LearnedDepth = single(LearnedDepth);
368         cvx_begin
369             cvx_quiet(false);
370             variable predictedM(NuPatch,1);
371             variable kt(Bsize,1);
372             %variable al(Bsize,1);
373             %variable ga(Bsize,1);
374             variable st(1,1);
375             minimize(st);%+ones(1,Bsize)*kt);
376              norm([Q2ndYy; Q2ndYz; Q2ndXz; Q2ndLinez;...
377                    spdiags(ones(NuPatch,1),[0],NuPatch,NuPatch)]...
378                    *predictedM+[sparse(Q1size+SLsize,1); -LearnedDepth(:)])<=st;
379             
380             %[[Q2ndYz] -spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
381             %   spdiags(ones(Bsize,1),[0],Bsize,Bsize) sparse(Bsize,Bsize);...
382             %  [Q2ndYz] spdiags(ones(Bsize,1),[0],Bsize,Bsize)...
383             %   sparse(Bsize,Bsize) spdiags(ones(Bsize,1),[0],Bsize,Bsize)]*[predictedM; kt; ga; al] == 0;
384             
385%             [Q2ndXz; Q2ndYz]*predictedM <=kt;
386%             [Q2ndXz; Q2ndYz]*predictedM >= -kt;
387             predictedM>=5;
388              %ga>=0;
389              %al<=0;
390         cvx_end   
391%         toc;
392
393% post prosessing on straight line
394
395% second optimization
396       
397        Date =date;
398        predictedM =reshape(predictedM,VertYNuDepth,[]);
399        depthMap = predictedM;
400        save([ScratchDataFolder '/_predicted_' DepthDirectory '/' depthfile '_' num2str(logScale) '_' Date '.mat'],'depthMap');
401        clear depthMap;
402       
403%=====================================================
404        % 2d to would 3d
405        [Position3DPredicted] = im_cr2w_cr(predictedM,RayCenter);
406   
407        % generate new LowResImgIndexSuperpixelSep_deoffset
408        %LowResImgIndexSuperpixelSep_deoffset = LowResImgIndexSuperpixelSep{i};
409   
410        % add on image feature
411        %global Imf;
412        %Imf= cat(1,Position3DPredicted,permute(ones(VertY,1)*[1:HoriX],[3 1 2]), permute([1:VertY]'*ones(1,HoriX),[3 1 2]),permute(double(zeros(VertY,HoriX,3)),[3 1 2]),permute(double(LowResImgIndexSuperpixelSep_deoffset),[3 1 2]),permute(double(LowResImgIndexSuperpixelSep{i}),[3 1 2]) );
413   
414        % calculate each plane parameter for each superpixel
415        %[PlaneParameterPredicted] = fit_all_planes(RayLoResCorner); % hard work around 2min
416   
417        % generate VRML
418        Date = date;
419        [VrmlName] = vrml_test_faceset_triangle(filename{i},Position3DPredicted,RayCenter,['PredictM_' DepthDirectory '_' num2str(logScale) '_' num2str(SkyExclude) '_' Date '_LearnedLogScaleNonsky_PredictNonsky_L21st_L12ndSmooth_StraightLineDoblueStitchOrientEst_gravity'],a,b,Ox,Oy);
420        system(['gzip -9 -c ' ScratchDataFolder '/vrml/' VrmlName ' > ' ScratchDataFolder '/vrml/' VrmlName '.gz']);
421        delete([ScratchDataFolder '/vrml/' VrmlName]);
422            %vrml_test_faceset_triangle(filename{i},PlaneParameterPredicted,LowResImgIndexSuperpixelSep{i},LowResImgIndexSuperpixelSep_deoffset,[DepthDirectory '_' Date]);
423end   
Note: See TracBrowser for help on using the repository browser.