织梦CMS - 轻松建站从此开始!

罗索

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

落鹤生 发布于 2014-08-12 09:15 点击:次 
本code通过直方图变换增强了图像对比度,实现了单通道图像增强。将图像灰度阈值拉伸到0-255,图像检测结果见底部 Keywords: 图像增强 增强对比度 直方图变换
TAG: 直方图均衡化  图像增强  直方图变换  增强对比度  

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

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

  1. int ImageStretchByHistogram(IplImage *src1,IplImage *dst1) 
  2. /************************************************* 
  3. Function:      通过直方图变换进行图像增强,将图像灰度的域值拉伸到0-255 
  4. src1:               单通道灰度图像                   
  5. dst1:              同样大小的单通道灰度图像  
  6. *************************************************/ 
  7.     assert(src1->width==dst1->width); 
  8.     double p[256],p1[256],num[256]; 
  9.      
  10.     memset(p,0,sizeof(p)); 
  11.     memset(p1,0,sizeof(p1)); 
  12.     memset(num,0,sizeof(num)); 
  13.     int height=src1->height; 
  14.     int width=src1->width; 
  15.     long wMulh = height * width; 
  16.      
  17.     //statistics 
  18.     for(int x=0;x<src1->width;x++) 
  19.     { 
  20.         for(int y=0;y<src1-> height;y++){ 
  21.             uchar v=((uchar*)(src1->imageData + src1->widthStep*y))[x]; 
  22.                 num[v]++; 
  23.         } 
  24.     } 
  25.     //calculate probability 
  26.     for(int i=0;i<256;i++) 
  27.     { 
  28.         p[i]=num[i]/wMulh; 
  29.     } 
  30.  
  31.     //p1[i]=sum(p[j]);  j<=i; 
  32.     for(int i=0;i<256;i++) 
  33.     { 
  34.         for(int k=0;k<=i;k++) 
  35.             p1[i]+=p[k]; 
  36.     } 
  37.  
  38.     // histogram transformation 
  39.     for(int x=0;x<src1->width;x++) 
  40.     { 
  41.         for(int y=0;y<src1-> height;y++){ 
  42.             uchar v=((uchar*)(src1->imageData + src1->widthStep*y))[x]; 
  43.                 ((uchar*)(dst1->imageData + dst1->widthStep*y))[x]= p1[v]*255+0.5;             
  44.         } 
  45.     } 
  46.     return 0; 
  47.  
  48. void CCVMFCView::OnImageAdjustContrast() 
  49.     if(workImg->nChannels>1) 
  50.         OnColorToGray(); 
  51.     Invalidate(); 
  52.     dst=cvCreateImage(cvGetSize(workImg),workImg->depth,workImg->nChannels); 
  53.     ImageStretchByHistogram(workImg,dst); 
  54.     m_dibFlag=imageReplace(dst,&workImg); 
  55.     Invalidate(); 

Experiment Result:

原图灰度化

                                    原图灰度化

检测结果1

                                     检测结果1

灰度化并增强对比度

                                灰度化并增强对比度

检测结果2

                                   检测结果2

(abcjennifer)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201408/17021.html]
本文出处:CSDN博客 作者:abcjennifer 原文
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容