i=imread('dragon.jpg');
m125=i>125;
i125=i.*uint8(m125);
% imshow(i125);
% figure,imshow(i);
m100=i<100;
m50=i<50;
m15=m100-m50;
i15=i.*uint8(m15);
% imshow(i15);
h=imhist(i);
H(1)=h(1);
for j=2:256
    H(j)=H(j-1)+h(j);
end

m=H(256);
for j=1:256
	N(j)=H(j)/m;
end
s=0.5;
p=1;
while N(p) < s
    p=p+1;
end
mp=i>p;
% imshow(mp);
%hist(double(i));
d=i<20;
D=d* 0.1;
for j=2:10
    m=i<(j*20);
    d=(m-(D>0));
    D=D + double(d*0.1*j);
end
imshow(D); colormap('hot')
Deq=histeq(D); %Egalise histogramme
