function predictedLaplaceDepthMap = applyLaplacianSmoothing(d_naive, nImages) % This function would not make sense by itself. % It is just to give a better idea of what Q matrix is in the IJCV paper at: % http://ai.stanford.edu/~asaxena/learningdepth/ % In a simplified example: If d = [d_1 d_2 d_3] gives the depth of a 3x1 image, for example. % Then if Q = [1 -1 0; 0 1 -1], % then Q d = [d_1 - d_2; d_2 - d_3 ] % then || Q d ||_1 = |d_1-d_2| + |d_2-d_3| % therefore you get differences in depth of neighboring patches. % % (This does not uses learned variances for inference.) % Author = Ashutosh Saxena; however do not bug him about the code. % This code is copyrighted by Ashutosh Saxena, Stanford University % It is available for non-commercial use only. For commericial use, please % contact the authors. % Any publication or report resulting from Use of this code, should cite: % Learning Depth from Single Monocular Images, Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng, NIPS 2005. % 3-D Depth Reconstruction from a Single Still Image, Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng, To appear in IJCV 2007. % For more info, visit: http://ai.stanford.edu/~asaxena/learningdepth/ global nGridRow nGridCol configurationFile; d_naive_img = reshape(permute( reshape( d_naive, [nGridCol, nImages, nGridRow]), [3 1 2]), ... [nGridRow*nGridCol nImages]); clear d_naive; totalnDepths = nGridRow*nGridCol; I = sparse(eye(totalnDepths)); I_minus_Py = sparse(I - I([(nGridCol+1):end (end-nGridCol+1):end],:) ); %== ERROR ... ERROR XShiftIndices = []; for r = 0:(nGridRow-1) XShiftIndices = [XShiftIndices r*nGridCol + [2:nGridCol, nGridCol] ]; end I_minus_Px = sparse(I - I(XShiftIndices,:) ); % first try without variance for n= 1:nImages %boundary case not properly taken care of if mod(n,10) == 0, disp(num2str(n)); end tmp = linprog( [ repmat(0,totalnDepths,1); repmat(1,3*totalnDepths,1)], ... [ speye(totalnDepths), -speye(totalnDepths), 0*speye(totalnDepths), 0*speye(totalnDepths); ... -speye(totalnDepths), -speye(totalnDepths), 0*speye(totalnDepths), 0*speye(totalnDepths); ... I_minus_Px, 0*speye(totalnDepths), -speye(totalnDepths), 0*speye(totalnDepths); ... -I_minux_Px, 0*speye(totalnDepths), -speye(totalnDepths), 0*speye(totalnDepths); ... I_minus_Py, 0*speye(totalnDepths), 0*speye(totalnDepths), -speye(totalnDepths); ... -I_minus_Py, 0*speye(totalnDepths), 0*speye(totalnDepths), -speye(totalnDepths) ], ... [d_naive_img(:,n); d_naive_img(:,n); repmat(0,totalnDepths*4,1)] ); laplaceDepthVector(:,n) = tmp(1:totalnDepths); end predictedLaplaceDepthMap = reshape(laplaceDepthVector, [nGridRow nGridCol nImages]);