1、突出图像中特定灰度范围的亮度通常是重要的,例如增强特征。
2、灰度级分成的两种基本方法:
(1)将感兴趣范围内的所有灰度值显示为一个值,其他灰度值显示为另一个值,该变换产生了一幅二值图像。
(2)激昂感兴趣范围的灰度变亮或变暗,保持图像中的其他灰度级不变。
C/C++ DEMO:
//通用
#include
#include
//图像操作
#include
#include
#include
using namespace :: std;
using namespace :: cv;
int
main()
{
//图像读取
Mat image =
imread("Fig0312.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 rang_min = 150;
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] >
rang_min)
data[i] = 255;
//else
//data[i] = 0;
}
}
//显示图像
namedWindow("Process Image");
imshow("Process Image",
image);
//保存图像
imwrite("result.JPG", image);
waitKey(0);
return 0;
}
原始图像:
处理后图片: