你好,游客 登录 注册 搜索
背景:
阅读新闻

OpenCV 图像增强算法 图像检测结果

[日期:2015-01-18] 来源:Linux社区  作者:abcjennifer [字体:大 中 小]

本代码通过直方图变换增强了图像对比度,实现了单通道图像增强。将图像灰度阈值拉伸到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++)
 {
  p[i]=num[i]/wMulh;
 }

 //p1[i]=sum(p[j]); j<=i;
 for(int i=0;i<256;i++)
 {
  for(int k=0;k<=i;k++)
   p1[i]+=p[k];
 }

 // histogram transformation
 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];
    ((uchar*)(dst1->imageData + dst1->widthStep*y))[x]= p1[v]*255+0.5;           
  }
 }
 return 0;
}

void CCVMFCView::OnImageAdjustContrast()
{
 if(workImg->nChannels>1)
  OnColorToGray();
 Invalidate();
 dst=cvCreateImage(cvGetSize(workImg),workImg->depth,workImg->nChannels);
 ImageStretchByHistogram(workImg,dst);
 m_dibFlag=imageReplace(dst,&workImg);
 Invalidate();
}

Experiment Result:

 

原图灰度化

                                   原图灰度化

检测结果1

                                     检测结果1

灰度化并增强对比度

                                灰度化并增强对比度

检测结果2

                                   检测结果2

--------------------------------------分割线 --------------------------------------

Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

--------------------------------------分割线 --------------------------------------

OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111966.htm

linux
相关资讯       OpenCV图像增强  OpenCV图像检测 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款