function cropfea = cropfea(im, depth, scale, model)

im = im2double(im);
depth = double(depth)/1000; % normalize to meter
if model.imagetag == 1 & model.depthtag == 1
   imfea = imfeatures(im, model.grid);
   depthfea = depthfeatures(depth, model.grid, scale);
   cropfea = cat(3, imfea, depthfea);

elseif model.imagetag == 1 & model.depthtag == 0
   cropfea = imfeatures(im, model.grid);

elseif model.imagetag == 0 & model.depthtag == 1
   cropfea = depthfeatures(depth, model.grid, scale);
end

function imfea = imfeatures(im, grid)

% hog features over images
imfea = features(im, grid);

%% color features over images
%border = 2;
%im = rgb2hsv(im);
%imcolor = cfeatures(im, grid);
%meanfea = zeros(1, size(imcolor,3));
%for i = 1:length(meanfea)
%    aaa = imcolor(border+1:end-border,border+1:end-border,i);
%    meanfea(i) = mean(aaa(:));
%end
%meanfea = repmat(meanfea, [size(imcolor,1)*size(imcolor,2) 1]);
%imcolor = reshape(meanfea, [size(imcolor,1) size(imcolor,2) size(imcolor,3)]);
% set border distance to be zeros
%imcolor(1:border,:,:) = 0.0;
%imcolor(end-border+1:end,:,:) = 0.0;
%imcolor(:,1:border,:) = 0.0;
%imcolor(:,end-border+1:end,:) = 0.0;

%% concatenate all of vision features
%imfea = cat(3, imfea, imcolor);

function depthfea = depthfeatures(depth, grid, scale)

% hog feature over depths
depthfea = hfeatures(depth, grid);

% scale features over depths 
border = 2;
depthscale = sfeatures(depth/scale, grid);
meanfea = zeros(1, size(depthscale,3));
for i = 1:length(meanfea)
    aaa = depthscale(border+1:end-border,border+1:end-border,i);
    meanfea(i) = mean(aaa(:));
end
meanfea = repmat(meanfea, [size(depthscale,1)*size(depthscale,2) 1]);
depthscale = reshape(meanfea, [size(depthscale,1) size(depthscale,2) size(depthscale,3)]);
% set border distance to be zeros
depthscale(1:border,:,:) = 0.0;
depthscale(end-border+1:end,:,:) = 0.0;
depthscale(:,1:border,:) = 0.0;
depthscale(:,end-border+1:end,:) = 0.0;

% concatenate all of vision features
depthfea = cat(3, depthfea, depthscale);

