function [featureVector] = makeScaledFeatureTexture(img, type, scale, numberOfStatistics) % This code is copyrighted by Stanford University. % Author: Ashutosh Saxena, Justin Drieymeyer % Code cannot be used for commercial purposes. % Use of the code, if used with permission from authors, must acknowledge: % Learning to Grasp Novel Objects using Vision, % Ashutosh Saxena, Justin Driemeyer, Justin Kearns, Chioma Osondu, Andrew Y. Ng. In 10th International Symposium on Experimental Robotics, ISER, 2006. % Robotic Grasping of Novel Obects, % Ashutosh Saxena, Justing Driemeyer, Justin Kearns, Andrew Y. Ng, In Neural Information Processing Systems (NIPS), 2006. % More details at: http://ai.stanford.edu/~asaxena/learninggrasp/ % Version 0.1: Aug 2006. global columnWidth nGridCol nGridRow rowWidth global scale2Factor global nDim nLaw nHarris if nargin < 4 numberOfStatistics = 1; end if nargin < 3 scale = [1 2 5]; 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;