function featureVector = ToyotaFeature_OneWindow(Window,resolution)
%function featureVector = ToyotaFeature(Window,resolution)
%
%input: an image, the feature resolution
%   default resolution is 16*16
%output: toyota feature.
%  simply put:  resize, filter, maxfitler, resize


if(nargin < 2)
  resolution = [16 16];
end
if(length(resolution) == 1)
  resolution = [resolution resolution];
end

if(size(Window,3) > 1)
  fprintf('only for grayscale windows\n');
  error;
end


Window = imresize(Window, resolution*4,'bilinear');
LayerImg = ApplySobelFilts(Window);
LayerImg = maxfilter(LayerImg,5);
featureVector = imresize(LayerImg,resolution,'bilinear');
featureVector = featureVector(:);




function im_layers = ApplySobelFilts(crop)
filts{1} = [1,1,1;0,0,0;-1,-1,-1];
filts{2} = [-1,0,1;-1,0,1;-1,0,1];
filts{3} = [0,1,1;-1,0,1;-1,-1,0];
filts{4} = [1,1,0;1,0,-1;0,-1,-1];
filts{5} = [-1,-1,-1;-1,8,-1;-1,-1,-1];
filts{6} = [0,0,0;0,1,0;0,0,0];
for i = 1:length(filts)
  f2 = (filts{i}(:)).^2;
  filts{i} = filts{i} / sqrt(sum(f2));
end
s = size(crop);
im_layers = zeros(s(1),s(2),length(filts));
crop = im2double(crop);
for i = 1:length(filts)
  im_layers(:,:,i) = imfilter(crop,filts{i},'symmetric');
  if(i ~= 6)
    im_layers(:,:,i) = abs(im_layers(:,:,i));
  end
end