source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Inference/ResearchTrials/test_L1_minimizer_withoutconstraints_rand.m @ 37

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

Added original make3d

File size: 7.1 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 [t]= test_L1_minimizer_withoutconstraints(filename,m,n)
40
41global A b S inq
42
43RealProblemFlag = 0
44if nargin <2
45   m = 800;
46   n = 500;
47end
48
49if ~RealProblemFlag
50   A = rand(m,n);
51   b = rand(m,1);
52   save temp.mat A b
53   S = [];
54   q = [];
55   Para = [];
56   %load temp.mat
57else
58   %filename = 'img-combined1-p-220t0_';
59   if nargin <1
60   filename = 'GatePackard000_';
61   end
62    ScratchFolder = '/afs/cs/group/reconstruction3d/scratch/IMStorage/';
63    OutPutFolder = '/afs/cs.stanford.edu/group/reconstruction3d/scratch/3DmodelMultipleImage/';
64%   ScratchFolder = 'C:\Documents and Settings\Ash\My Documents\Reconstruction3d\DataTemp\';
65%   OutPutFolder = 'C:\Documents and Settings\Ash\My Documents\Reconstruction3d\DataTemp\';
66   load([ScratchFolder 'Catsh1stOpt_' filename '.mat']);
67   A = [ NewPosiM.*repmat(WeightsSelfTerm,1,size(NewPosiM,2));...
68         NewCoPM.*repmat(NewCoPEstDepth,1,size(NewCoPM,2))*Center;...
69         NewHoriStickM.*repmat( NewEstDepHoriStick.*NewWeightHoriNeighborStitch,1,size( NewHoriStickM,2));...
70         NewVertStickM.*repmat( NewEstDepVertStick.*NewWeightVertNeighborStitch,1,size( NewVertStickM,2))];
71A1=  NewPosiM.*repmat(WeightsSelfTerm,1,size(NewPosiM,2));
72A2=  NewCoPM.*repmat(NewCoPEstDepth,1,size(NewCoPM,2))*Center;
73A3=  NewHoriStickM.*repmat( NewEstDepHoriStick.*NewWeightHoriNeighborStitch,1,size( NewHoriStickM,2));
74A4=  NewVertStickM.*repmat( NewEstDepVertStick.*NewWeightVertNeighborStitch,1,size( NewVertStickM,2));
75   b = [ ones(size(NewPosiM,1),1);...
76         NewCoPMBound.*NewCoPEstDepth*Center;...
77         NewHoriStickMBound.*NewEstDepHoriStick.*NewWeightHoriNeighborStitch;...
78         NewVertStickMBound.*NewEstDepVertStick.*NewWeightVertNeighborStitch];
79   % inequalities
80%   NuSubSupSize = size(A,2) / 3;
81   temp = zeros(1, NuSubSupSize*3);
82   temp(3*(1:NuSubSupSize)-1) = YPointer(Sup2Para(SubSup));
83   temp = sparse(1:length(temp), 1:length(temp), temp);
84   temp( sum(temp,2) ==0,:) = [];
85   S = [temp;...
86        NewRayAllM;...
87        -NewRayAllM];
88   q = [ sparse(size(temp,1), 1);...
89         - 1/ClosestDist*ones(size(NewRayAllM,1),1);...
90         1/FarestDist*ones(size(NewRayAllM,1),1)];
91   
92Para.A1endPt = size(A1,1);
93Para.A2endPt = Para.A1endPt+size(A2,1);
94Para.A3endPt = Para.A2endPt+size(A3,1);
95Para.A4endPt = Para.A3endPt+size(A4,1);
96Para.ClosestDist = ClosestDist;
97Para.FarestDist = FarestDist;
98clear A1 A2 A3 A4;
99end
100% test on ashu's code
101
102%S = S(floor(end/2):floor(3*end/5),:);
103%q = q(floor(end/2):floor(3*end/5));
104%disp('Reducing inequalities by 1/3');
105
106%ashIteratorTime = tic;
107%[x_ashIterator, fail, info] = Ash_L1_Minimizer_min(A1, A2, A3, A4, b, 1e-12, 1);
108% log_barrier (Para, A, b, S, q, '', [], [], [], 1, 1);
109%inq = q;
110tic;
111[x_ashIterator, alfa, status, history, T_nt_hist] = SigmoidSolver( Para, [], [], [], '', [], [], 0);
112
113
114%toc(ashIteratorTime)
115toc
116t(1,1) = toc;
117alfa
118tic
119[x_ashIterator, status, history] = L1Barrier_wo_Constrain(Para,[],[],[],0);
120toc
121t(2,1) = toc;
122%return;
123% generate VRml
124%    PlanePara = reshape(x_ashIterator,3,[]);
125%    FitDepthPPCP = FarestDist*ones(1,55*305);
126%    FitDepthPPCP(~maskSkyEroded) = (1./sum(PlanePara(:,Sup2Para(SupEpand(~maskSkyEroded ))).*Ray(:,~maskSkyEroded ),1))';
127%    FitDepthPPCP = reshape(FitDepthPPCP,55,[]);
128%    [Position3DFitedPPCP] = im_cr2w_cr(FitDepthPPCP,permute(Ray,[2 3 1]));
129%    Position3DFitedPPCP(3,:) = -Position3DFitedPPCP(3,:);
130%          Position3DFitedPPCP = permute(Position3DFitedPPCP,[2 3 1]);
131%          RR =permute(Ray,[2 3 1]);
132%          temp = RR(:,:,1:2)./repmat(RR(:,:,3),[1 1 2]);
133%          WrlFacestHroiReduce(Position3DFitedPPCP,PositionTex,SupOri, [ filename],[ filename 'AshuMinimizer'], ...
134%                              [ OutPutFolder '/'], 0, 0);
135%    [OutPutFolder '/' filename 'AshuMinimizer']
136
137%x_ashIterator = Ash_L1_Minimizer(A,b);
138
139% solve here for x using another method, and compare outputs
140% solve by sedumi
141
142% A = [An1; An2; An3; An4];
143% clear An1 An2 An3 An4;
144
145% =============================
146
147% sedumiTime = tic;
148tic
149xsedumi = sdpvar( size(A,2), 1);
150opt = sdpsettings('solver','sedumi','cachesolvers',1, 'verbose', 0);
151obj = norm(A*xsedumi-b, 1);
152%F = set(S*xsedumi+q<=0);
153%[model,recoverymodel] = export(F,obj,opt);
154
155sol = solvesdp([], norm(A*xsedumi-b, 1),opt);
156%[x,y] = sedumi(model.A,model.b,model.C,model.K);
157%assign(recover(recoverymodel.used_variables),y);
158xsedumi = double(xsedumi);
159toc
160t(3,1) = toc;
161% toc(sedumiTime)
162
163% generate VRml
164%   PlanePara = reshape(xsedumi,3,[]);
165%   FitDepthPPCP = FarestDist*ones(1,55*305);
166%   FitDepthPPCP(~maskSkyEroded) = (1./sum(PlanePara(:,Sup2Para(SupEpand(~maskSkyEroded ))).*Ray(:,~maskSkyEroded ),1))';
167%   FitDepthPPCP = reshape(FitDepthPPCP,55,[]);
168%   [Position3DFitedPPCP] = im_cr2w_cr(FitDepthPPCP,permute(Ray,[2 3 1]));
169%   Position3DFitedPPCP(3,:) = -Position3DFitedPPCP(3,:);
170%         Position3DFitedPPCP = permute(Position3DFitedPPCP,[2 3 1]);
171%         RR =permute(Ray,[2 3 1]);
172%         temp = RR(:,:,1:2)./repmat(RR(:,:,3),[1 1 2]);
173%         WrlFacestHroiReduce(Position3DFitedPPCP,PositionTex,SupOri, [ filename],[ filename 'sedumi'], ...
174%                             [ OutPutFolder '/'], 0, 0);
175%   [OutPutFolder '/' filename 'sedumi']
176   
177norm(A*x_ashIterator-b,1)
178norm(A*xsedumi-b,1)
179plot(x_ashIterator,'r');
180hold on;
181plot(xsedumi,'g');
182
183norm(x_ashIterator-xsedumi,1) / norm(xsedumi,1)
184norm(A*x_ashIterator-b,1)
185norm(A*(x_ashIterator-xsedumi),1) / norm(A*x_ashIterator-b,1)
Note: See TracBrowser for help on using the repository browser.