function [I, IPx, IPy] = formPermutationMatricesScale1(nGridRow, nGridCol, nD) % Version 0.1, Feb 2006. % 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 and dataset, visit: http://ai.stanford.edu/~asaxena/learningdepth/ % For a better version of the algorithm, also visit: % http://ai.stanford.edu/~asaxena/reconstruction3d/ % This is from IJCAIR version of the code, so might differ. % This function forms the "Q" matrices in the IJCV paper in Appendix for inference/learning. tmp = nGridRow; nGridRow = nGridCol; nGridCol = tmp; % HACK order of dimensions!!!!!#R^%E#%$# if nargin < 3 nD = 1; %neighbor is by default the nearest end totalnDepths = nGridRow*nGridCol; totalnDepth = totalnDepths; %=======start forming permuation matrices==================== %disp('Making Permutation matrices for 2.5 scales........'); I = speye(totalnDepths); appI = [I; zeros(1,totalnDepths)]; zR = totalnDepths+1; ind0 = []; ind2 = []; %======= for Y direction =========== for r = 0:(nGridRow-1-nD) c = r*nGridCol + (1:nGridCol); ind0 = [ind0, c]; ind2 = [ind2, (c+nGridCol)]; end IPy_short = (appI(ind0,:) - appI(ind2,:) ); IPy = [IPy_short; zeros(nD*nGridCol, totalnDepths) ]; %==========for X-direction =================== ind0 = []; ind4 = []; for r = 0:(nGridRow-1) c = r*nGridCol + (1:(nGridCol-nD) ); ind0 = [ind0, c, repmat(zR,1,nD)]; ind4 = [ind4, (c+1), repmat(zR,1,nD)]; end IPx_short = (appI(ind0,:) - appI(ind4,:) ); IPx = IPx_short;