s=imread('G:\毕业设计\panfeng\边缘\Lena.tif');
[m,n]=size(s);
num=m*n;
r=zeros(1,512);
e=zeros(1,512);
d=zeros(size(s));
for i=1:m
for j=1:n
r(s(i,j)+1)=r(s(i,j)+1)+1; %原图像概率密度
end
end
r=r./num;
for i=1:m
for j=1:i
e(i)=e(i)+r(j); %累积分布
end
end
for i=1:256
e(i)=floor(e(i)*255+0.5); %映射关系
end
for i=1:m
for j=1:n
d(i,j)=e(s(i,j)+1);
end
end
s=uint8(s);
d=uint8(d);
subplot(2,2,1);
imshow(s);
title('source');
subplot(2,2,2);
imhist(s);
title('histogram of source');
subplot(2,2,3);
imshow(d);
title('dest');
subplot(2,2,4);
imhist(d);
title('histogram of dest');