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

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

本code通过直方图变换增强了图像对比度,实现了单通道图像增强。将图像灰度阈值拉伸到0-255,图像检测结果见底部

Keywords: 图像增强 增强对比度 直方图变换

int ImageStretchByHistogram(IplImage *src1,IplImage *dst1)/*************************************************Function:      通过直方图变换进行图像增强,将图像灰度的域值拉伸到0-255src1:               单通道灰度图像                  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


           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值