function y=histeq(x)
N = prod(size(x));
s = sort(reshape(double(x),1,N));
x0 = s(round(N*.01));
x1 = s(round(N*.99));
y = (double(x)-x0)*255/(x1-x0);
y(find(y<0)) = 0;
y(find(y>255)) = 255;