Opencv 图像增强算法 图像检测结果
来源:互联网 发布:哥伦比亚号 知乎 编辑:程序博客网 时间:2024/05/01 00:34
本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++)
- {
- 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();
- }
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;//statisticsfor(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 probabilityfor(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 transformationfor(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
灰度化并增强对比度
检测结果2
- Opencv 图像增强算法 图像检测结果
- Opencv 图像增强算法 图像检测结果
- Opencv 图像增强算法 图像检测结果
- Opencv 图像增强算法 图像检测结果及代码
- OpenCV直方图图像增强算法
- 图像颜色增强算法Opencv
- OpenCV,常用图像增强算法的实现
- ACE图像增强算法Opencv实现
- opencv 灰度图像增强
- opencv-图像增强
- opencv图像增强demo
- OpenCV笔记 图像增强
- OpenCV图像边缘检测(Canny算法)
- OpenCV图像边缘检测(sobel算法)
- OpenCV图像边缘检测(Laplace算法)
- retinex图像增强算法
- Retinex图像增强算法
- 图像增强算法
- MATLAB调用C/C++函数的方法
- 直方图;索引
- linux下 .xls文件去除某列为空的行
- RHEL6 iptables 彻底关闭linux防火墙
- jsp行传值时,出现乱码
- Opencv 图像增强算法 图像检测结果
- 去图片水印
- 回看大学这四年 ACM
- 忆往昔(上篇)
- ORACLE日期时间函数大全
- php新手 想找高手指点
- 斜杠/和反斜杠\的区别
- makefile 获取指定目录下源文件名称
- Dell 服务电话列表