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