function saMat = SSDB_EntOfUlterodeOfSeg(X,options);
%counts the number of unique values in a local region

d.OrigSize = [128 128];
if(nargin < 2),options = [];,end
options = ResolveMissingOptions(options,d);
nIm = size(X,2);
saMat.SegFeature = zeros(size(X));
for i = 1:nIm;
  fprintf('SSDB_LocalSegmentCount image %d of %d\r',i,nIm);
  stim = SplitBrokenSegs(reshape(X(:,i),[128 128]));
  EntIm = max(EntOfUlterode(stim),[],3);
  [saMat.SegFeature(:,i)] = EntIm(:);
end
  fprintf('SSDB_LocalSegmentCount image %d of %d\n',i,nIm);

function MLI = EntOfUlterode(IdxImg);
%function MLI = EntOfUlterode(IdxImg);

u = unique(IdxImg);
MLI = zeros(size(IdxImg,1), size(IdxImg,2), length(u));

T = zeros(size(IdxImg,1), size(IdxImg,2), length(u));
for i = u'
  T(:,:,i) = (IdxImg == u(i));
  MLI(:,:,i) = entropyfilt(bwulterode(T(:,:,i)));
end

