function [y,h_v,h_h]=laws(x,id,LocalEnergy)
% LAWS	Laws filtering and feature extraction
%	y=laws(x,id), where id is a string (see below) filters the image x
%	by the filter identified by the id, and returns the filter response.
%	Valid filter ids are all four-character combinations of the two-
%	character filter identifiers
%	  'L5'	the filter [ 1  4  6  4  1]
%	  'E5'	the filter [-1 -2  0  4  1]
%	  'S5'	the filter [-1  0  2  0 -1]
%	  'W5'	the filter [-1  2  0 -2  1]
%	  'R5'	the filter [ 1 -4  6 -4  1]
%	  '__'	the filter [ 0  0  1  0  0] (all pass)
%	The first part identifies filter to be used vertically and the
%	second the filter to be used horizontally.
%	
%	y=laws(x,id,[M_w N_w]) also applies a M_w by N_w absolute average
%	(local energy) computation of the filter response.

% Select the filter coefficients
for dim=1:2
  if dim==1, FilterId=upper(id(1:2)); else, FilterId=upper(id(3:4)); end
  if strcmp(FilterId,'L5'), h(dim,1:5)=[ 1  4  6  4  1];
  elseif strcmp(FilterId,'E5'), h(dim,1:5)=[-1 -2  0  4  1];
  elseif strcmp(FilterId,'S5'), h(dim,1:5)=[-1  0  2  0 -1];
  elseif strcmp(FilterId,'W5'), h(dim,1:5)=[-1  2  0 -2  1];
  elseif strcmp(FilterId,'R5'), h(dim,1:5)=[ 1 -4  6 -4  1];
  elseif strcmp(FilterId,'__'), h(dim,1:5)=[ 0  0  1  0  0];
  end
end
h_v=h(1,:)';
h_h=h(2,:);

% Perform the filtering
y=filter2(h_v,filter2(h_h,x));

% Local energy function, if requested
if exist('LocalEnergy')==1
  y=avgsmth(abs(y),LocalEnergy(1),LocalEnergy(2));
end