本code通过直方图变换增强了图像对比度,实现了单通道图像增强。将图像灰度阈值拉伸到0-255,图像检测结果见底部
Keywords: 图像增强 增强对比度 直方图变换
int ImageStretchByHistogram(IplImage *src1,IplImage *dst1)
/*************************************************
Function: 通过直方图变换进行图像增强,将图像灰度的域值拉伸到0-255
src1: 单通道灰度图像
dst1: 同样大小的单通道灰度图像
*************************************************/
{
assert(src1->width==dst1->width);
double p[256],p1[256],num[256];
memset(p,0,sizeof(p));
memset(p1,0,sizeof(p1));
memset(num,0,sizeof(num));
int height=src1->height;
int width=src1->width;
long wMulh = height * width;
//statistics
for(int x=0;x<src1->width;x++)
{
for(int y=0;y<src1-> height;y++){
uchar v=((uchar*)(src1->imageData + src1->widthStep*y))[x];
num[v]++;
}
}
//calculate probability
for(int i=0;i<256;i+