function ii=reducePolyChar(px,py,tol)
% reducePolyChar <reduce number of points in a polygon from image.>
% Usage:: index=reducePolyChar(px,py,tol[5e-4])
%

% revision history:
% 12/05/18 Mark D. Shattuck <mds> reducePolyChara.m

%% Parse Input
if(~exist('tol','var') || isempty(tol))
	tol=5e-4;
end

%% Main

ns=1;
Np=length(px);
ii=false(1,Np);
ii(1)=true;
nc=0;
while(nc<=Np)
  np=1;
  err=0;
  while(err<tol && np<=Np)
    nc=nc+1;
    np=np+1;
    nn=np+ns-1;
    nnn=ns:nn;
    ll=(nnn-ns)'/(nn-ns);
    nn=mod(nn-1,Np)+1;
    nnn=mod(nnn-1,Np)+1;
    lpx=px(ns)+ll.*(px(nn)-px(ns));
    lpy=py(ns)+ll.*(py(nn)-py(ns));
    err=sum(abs(lpx-px(nnn)+1i*(lpy-py(nnn)))/length(nnn));
  end
  nn=mod(nn-1-1,Np)+1;
  ii(nn)=true;
  ns=nn;
  nc=nc-1;
end

