function [output] = HStanModel(input,options)
%function [output] = HStanModel(input,options)
%
%strengthens the continuous edges using a histogram and max strategy
%vertical edges are strengthened in layer 1, and horizontal in layer 2


d.DecimationFactor = 1;
d.CellSupportSize = 7;
d.Normalization = 'L2';
d.OrientationSmoothingBandwidth = .2;
d.MaxFilterOrder = 1;
d.bUseLinearFilterInstead = 0;
d.bUseMinFilter = 1;

if(nargin < 2), options = [];, end
options = ResolveMissingOptions(options,d);

input = NormalizeInput(input);
% input = input.^options.MaxFilterOrder;
mask = ones(options.CellSupportSize,1);
%if(options.bUseLinearFilterInstead)
%  output(:,:,1) = conv2crop(mask,1,input(:,:,1));
%  output(:,:,2) = conv2crop(1,mask,input(:,:,2));
%else
%  reducedInput = log(input + eps);
%  output(:,:,1) = conv2crop(mask,1,reducedInput(:,:,1));
%  output(:,:,2) = conv2crop(1,mask,reducedInput(:,:,2));
%  output = exp(output/options.CellSupportSize);
%  reducedInput = log(reducedInput);
%end
if(options.bUseMinFilter)
  l = floor(options.CellSupportSize / 2);  
  r = ceil(options.CellSupportSize / 2);  
  output(:,:,1) = -maxfilter(-input(:,:,1),[0 l 0 r]);
  output(:,:,2) = -maxfilter(-input(:,:,2),[l 0 r 0]);
end

function x = NormalizeInput(x);
x = x - min(x(:)) + 10^-6;
x = x/max(x(:));
