数字图像处理之点运算---直方图均衡化

一.理论基础
1.直方图均衡化
2.直方图规定化
(理论基础推导较多,可自行百度。这里只给出matlab实现和直方图均衡化和规定化的用处)
二.matlab实现
直方图均衡化:

%直方图均衡
I=imread('pout.tif');
I=im2double(I);
%对比度变大的图像
I1=2*I-55/255;
subplot(4,4,1);
imshow(I1);
title('对比度变大','FontSize',8);
subplot(4,4,2);
imhist(I1);
subplot(4,4,3);
imshow(histeq(I1));
title('直方图均衡化效果','FontSize',8);
subplot(4,4,4);
imhist(histeq(I1));
%对比度变小的图像
I1=0.5*I+55/255;
subplot(4,4,5);
imshow(I1);
title('对比度变小','FontSize',8);
subplot(4,4,6);
imhist(I1);
subplot(4,4,7);
imshow(histeq(I1));
title('直方图均衡化效果','FontSize',8);
subplot(4,4,8);
imhist(histeq(I1));
%线性增加亮度的图像
I1=I+55/255;
subplot(4,4,9);
imshow(I1);
title('增加亮度','FontSize',8);
subplot(4,4,10);
imhist(I1);
subplot(4,4,11);
imshow(histeq(I1));
title('直方图均衡化效果','FontSize',8);
subplot(4,4,12);
imhist(histeq(I1));
%线性减小亮度的图像
I1=I-55/255;
subplot(4,4,13);
imshow(I1);
title('减小亮度','FontSize',8);
subplot(4,4,14);
imhist(I1);
subplot(4,4,15);
imshow(histeq(I1));
title('直方图均衡化效果','FontSize',8);
subplot(4,4,16);
imhist(histeq(I1));

执行结果:

在这里插入图片描述
从上图我们可以发现同一图像在不同的亮度对比度的情况下,实现均衡化可以实现几乎相同的效果,也就是说通过直方图均衡化可以抵抗各种变换,从而消除图像的不同变形体之间的外观差异。而且通过上图发现均衡化后的图像都比原图对比度高,说明直方图均衡化有自适应对比度增强的作用。

直方图规定化

%直方图规定化
I=imread('pout.tif');
I1=imread('coins.png');
I2=imread('circuit.tif');
%计算直方图
[hgram1,x1]=imhist(I1);
[hgram2,x2]=imhist(I2);
%执行直方图均衡化
J1=histeq(I,hgram1);
J2=histeq(I,hgram2);
%绘图
figure;
subplot(2,3,1);
imshow(I);title('原图像');
subplot(2,3,2);
imshow(I1);title('标准图1');
subplot(2,3,3);
imshow(I2);title('标准图2');
subplot(2,3,5);
imshow(J1);title('规定化到1');
subplot(2,3,6);
imshow(J2);title('规定化到2');
%绘直方图
figure;
subplot(2,3,1);
imhist(I);title('原图');
subplot(2,3,2);
imhist(I1);title('标准图1');
subplot(2,3,3);
imhist(I2);title('标准图2');
subplot(2,3,5);
imhist(J1);title('规定化到1');
subplot(2,3,6);
imhist(J2);title('规定化到2');

执行结果:

在这里插入图片描述
在这里插入图片描述发现规定化后的图像直方图与原图直方图变得较为相似,直方图规定化的本质是一种拟合过程,因此变换得到的直方图与标准目标图像的直方图并不会完全一致,然而只是相似的拟合,仍然使规定化的图像在亮度与对比度上具有类似标准图像的特性,这也是直方图规定化的目的。

猜你喜欢

转载自blog.csdn.net/jxqbuct/article/details/89284489