1.低对比度图像的原因:照明不足、成像传感器动态范围过小、镜头光圈设置错误。
2.分段线性变换函数:增强原图各部分的对比度,即增强输入图像中感兴趣的灰度区域,相对抑制不感兴趣的灰度区域。优点是形式可以随意合成,缺点是需要更多的用户输入。
3、
分段线性变换函数形式:
给出需要转换的灰度范围,以确定线性转换的斜率。
4.分段的灰度拉伸可以更灵活地控制输出灰度直方图的分布,并有选择地拉伸一定的灰度范围改善输出图像。如果图像灰度集中在较暗的区域,导致图像偏暗,则可以通过灰度拉伸功能进行扩展(斜率>1)物体的灰度范围可以改善图像;如果图像灰度集中在明亮区域,导致图像明亮,也可以用灰度拉伸功能压缩(斜率<1)提高图像质量。
5.一般来说,限制<
C/C Demo: 将灰度级从原范围线性拉伸到整个灰度级。
//通用
#include
#include
///图像操作
#include
#include
#include
using namespace :: std;
using namespace :: cv;
int
main()
{
//图像读取
Mat image =
imread("Fig0310.tif");
////判断图像读取是否有问题
if(!image.data)
{
cout << "image read
is error!" <<
endl;
return 0;
}
////图像基本信息输出
cout << "image
Info:Height:" <<
image.size().height <<
" Width:"
<< image.size().width
<< endl;
///原始图像显示
namedWindow("Original
Image");
imshow("Original Image",
image);
imwrite("original.jpg",
image);
///处理图像
int data_max = 0,data_min = 255;
int nl = image.rows;
int nc = image.cols * image.channels();
if(image.isContinuous())
{
nc = nc * nl;
nl = 1;
}
int i,j;
uchar *data;
for(j = 0; j < nl; j )
{
data = image.ptr(j);
for(i = 0; i < nc; i )
{
if(data[i] >
data_max)
data_max = data[i];
if(data[i] <
data_min)
data_min = data[i];
}
}
cout <<
"data_max:"
<< data_max
<< "
data_min:" <<
data_min << endl;
int temp = data_max - data_min;
for(j = 0; j < nl; j )
{
data = image.ptr(j);
for(i = 0; i < nc; i )
{
data[i] = (data[i] - data_min) * 255 / temp;
}
}
//显示图像
namedWindow("Process Image");
imshow("Process Image",
image);
//保存图像
imwrite("result.JPG", image);
waitKey(0);
return 0;
}
原始图像:
图像处理后: