function [pnew,labnew] = segp1(pold,labimg,minsize)
%
% segp1 - process segments: remove small segs
% On input:
%     pold: segment properties
%     labimg: labeled image
%     minsize: minimum size to keep
% On output:
%     pnew: new segments
%     labnew: new labeled image
% Call:
%     [pnew,labnew] = segp1(pold,labimg,minsize)
%

[numsegs,dummy] = size(pold);

pnew = [];
[m,n] = size(labimg);
labnew = zeros(m,n);
count = 1;
for s = 1:numsegs
  if pold(s,3)>=minsize
    pnew = [pnew ; pold(s,:)];
    labnew = labnew+(labimg==s)*count;
    count = count+1;
  end
end
