function threshold_percent(I,percent,region);
% percent as a fraction

[height,width]=size(I);

if region=='l',
    percent=1-percent;
end

pixels=height*width*percent;
H=myhist(I);

i=1;
t=0;
while t<pixels,
   t=t+H(i);
   i=i+1;
end

i

O=threshold(I,i);
imagesc(O);