clear
clc
%图像读取
K=imread('C:\Users\winwin\Desktop\w.jpg');%读入一彩色图
I=K(:,:,1);%取出第一维的红色分量作为一个灰度图像
figure(1)
subplot(121)
imshow(I);
title('原始图像');
subplot(122)
imhist(I,64);%绘制直方图
title('原始图像的直方图');
J=histeq(I); %将灰度图像转换成具有64(默认)个离散灰度级的灰度图像
figure(2);
subplot(121);
imshow(J);
title('直方图均衡化后的图像')
subplot(122);
imhist(J,64)
title('均衡后的直方图')
%直方图规定化
hgram=50:2:250; %规定化函数
J1=histeq(I,hgram);
figure(3);
subplot(121);
imshow(J1);
title('直方图规定化后的图像');
subplot(122);
imhist(J1,64);
title('直方图规定化后的直方图');