function [featureVector] = makeScaledFeatureTexture(img, type, scale, numberOfStatistics) % 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/ global columnWidth nGridCol nGridRow rowWidth global scale2Factor global nDim nLaw nHarris if nargin < 4 numberOfStatistics = 1; end if nargin < 3 scale = 1; end if nargin < 2 type = 'laws'; end nGCol = nGridCol; nGRow = nGridRow; numoverlaps = 0; % If you want to work with % reduced image size, just % scale the image appropriately % below. numoverlaps = scale - 1; edgefactor = (2*numoverlaps + 1); % Assume that the image is correctly oriented. imheight = size(img, 1); imwidth = size(img, 2); % Step sizes in x and y stepwidth = imwidth/nGridCol; stepheight = imheight/nGridRow; %===========calculating filter banks [H2, H4, H1] = calculateFilterBanks(img, type); nDim = size(H2, 3) + 0; %forming spatial masks %========================================= %featureVectorTmp = zeros( nGRow, nGCol, 2*nLaw+3*nHarris); featureVectorTmp = zeros( nGRow, nGCol, nDim); for g = 1:nGRow for c = 1:nGCol gridLeft = round( (g - 1 - numoverlaps)*stepheight + 1); gridRight = round( (g + numoverlaps)*stepheight ); normfactor = 1.0; if gridLeft < 1 gridLeft = 1; normfactor = normfactor * edgefactor / (numoverlaps + g); elseif gridRight > (nGRow * stepheight) gridRight = round(nGRow*stepheight); normfactor = normfactor * edgefactor ... / (numoverlaps + nGRow - g + 1); end gridTop = round( (c - 1 - numoverlaps)*stepwidth + 1); gridBot = round( (c + numoverlaps)*stepwidth ); if gridTop < 1 gridTop = 1; normfactor = normfactor * edgefactor / (numoverlaps + c); elseif gridBot > (nGCol * stepwidth) gridBot = round(nGCol*stepwidth); normfactor = normfactor * edgefactor ... / (numoverlaps + nGCol - c + 1); end %LAWS----------- if nLaw featureVectorTmp(g,c,1:nLaw) = sum( sum( H2( gridLeft:gridRight, gridTop:gridBot, :), 2), 1); % featureVectorTmp(g,c,nLaw+(1:nLaw)) = sum( sum( H4( gridLeft:gridRight, gridTop:gridBot, 1:nLaw), 2), 1); end if nHarris %Can be optimized for row = gridLeft:gridRight for col = gridTop:gridBot; featureVectorTmp(g,c,2*nLaw+angleImage(row,col) ) = featureVectorTmp(g,c,2*nLaw+angleImage(row,col) ) + ... gradientMagImage(row,col); %featureVectorTmp(g,c,2*nLaw+nHarris+angleImage(row,col) ) = featureVectorTmp(g,c,2*nLaw+nHarris+angleImage(row,col) ) + ... gradientMagImage(row,col) .* (2*col<(gridTop+gridBot)); %featureVectorTmp(g,c,2*nLaw+2*nHarris+angleImage(row,col) ) = featureVectorTmp(g,c,2*nLaw+2*nHarris+angleImage(row,col) ) + ... gradientMagImage(row,col) .* (2*col>=(gridTop+gridBot)); end end featureVectorTmp(g,c,2*nLaw+(1:nHarris) ) = featureVectorTmp(g,c,2*nLaw+(1:nHarris) ) ./ ... (max( featureVectorTmp(g,c,2*nLaw+(1:nHarris) ) ) + upsilon); %featureVectorTmp(g,c,2*nLaw+nHarris+(1:nHarris) ) = featureVectorTmp(g,c,2*nLaw+nHarris+(1:nHarris) ) ./ ... % (max( featureVectorTmp(g,c,2*nLaw+nHarris+(1:nHarris) ) ) + upsilon); %featureVectorTmp(g,c,2*nLaw+2*nHarris+(1:nHarris) ) = featureVectorTmp(g,c,2*nLaw+2*nHarris+(1:nHarris) ) ./ ... % (max( featureVectorTmp(g,c,2*nLaw+2*nHarris+(1:nHarris) ) ) + upsilon); end % normalize featureVectorTmp(g,c,1:nLaw) = normfactor*featureVectorTmp(g,c,1:nLaw); end end featureVector = featureVectorTmp; %permute( featureVectorTmp, [3 1 2]); %featureVector = reshape( featureVector3, [size(featureVector2,1)*size(featureVector3,2) nGridCol] ); % if displayFlag % figure, % subplot(2,2,1), imshow(img); % subplot(2,2,2), imagesc(ycbcr_img(:,:,1)); % subplot(2,2,4), imagesc(ycbcr_img(:,:,2)); % subplot(2,2,3); plot( squeeze(featureVector(frame,:,:)) ); % axis tight; % end return;