我所知的opencv中分割函数:watershed(只是看看效果,不能返回每类pixel类属),cvsegmentImage,cvPyrSegmentation(返回pixel类属)

金字塔分割原理篇在这里,本文只提供代码。

Segment函数:

[cpp] view plain copy  
  1. #include<cv.h>
  2. #include <cvaux.h>
  3. #include <opencv\cxcore.hpp>
  4. #include <opencv.hpp>
  5. #include <nonfree.hpp>
  6. #include <core/core.hpp>
  7. #include <imgproc/imgproc.hpp>
  8. #include <imgproc/imgproc_c.h>
  9. #include <vector>
  10. #include <map>
  11. #include <highgui.h>
  12. using namespace std;
  13. using namespace cv;
  14. void Segment(IplImage* I)
  15. {
  16. parameters initialization//
  17. int mode = CV_RETR_LIST;
  18. int level = 2, block_size = 1000;
  19. CvMemStorage* storage = cvCreateMemStorage(block_size);
  20. CvSeq* components;
  21. double threshold1 = 100,threshold2 = 50;
  22. IplImage *src = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,1);
  23. cvCvtColor(I,src,CV_RGB2GRAY);
  24. IplImage* dst = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,1);
  25. src->width = dst->width = (I->width & -(1 << level));
  26. src->height = dst->height = (I->height & -(1 << level));
  27. //Segment/
  28. cvPyrSegmentation(src,dst,storage,&components,level,threshold1,threshold2);
  29. int ncomp = components->total;
  30. cout<<"segemented into "<<ncomp<<" components."<<endl;
  31. //Get Components/
  32. map<int, int>mapping;//map color value to component id (classify)
  33. for (int i = 0; i<ncomp; i++)//foreach connection component
  34. {
  35. CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(components,i);
  36. cvDrawRect(dst,cvPoint(cc->rect.x,cc->rect.y),cvPoint(cc->rect.x+cc->rect.width,cc->rect.y+cc->rect.height),cvScalar(255,255,0));
  37. mapping.insert(pair<int,int>(cc->value.val[0],i));
  38. }
  39. cvShowImage("segementation",dst);
  40. waitKey();
  41. cvReleaseMemStorage(&storage);
  42. }

彩色图分割版本:

[cpp] view plain copy  
  1. void Segment(IplImage* I)
  2. {
  3. parameters initialization//
  4. int mode = CV_RETR_LIST;
  5. int level = 2, block_size = 1000;
  6. CvMemStorage* storage = cvCreateMemStorage(block_size);
  7. CvSeq* components;
  8. double threshold1 = 10,threshold2 = 50;
  9. IplImage *src = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,3);
  10. src = cvCloneImage(I);
  11. IplImage* dst = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,3);
  12. src->width = dst->width = (I->width & -(1 << level));
  13. src->height = dst->height = (I->height & -(1 << level));
  14. //Segment/
  15. cvPyrSegmentation(src,dst,storage,&components,level,threshold1,threshold2);
  16. int ncomp = components->total;
  17. cout<<"segemented into "<<ncomp<<" components."<<endl;
  18. //Get Components/
  19. map<int, int>mapping;//map color value to component id (classify)
  20. for (int i = 0; i<ncomp; i++)//foreach connection component
  21. {
  22. CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(components,i);
  23. cvDrawRect(dst,cvPoint(cc->rect.x,cc->rect.y),cvPoint(cc->rect.x+cc->rect.width,cc->rect.y+cc->rect.height),cvScalar(255,255,0));
  24. mapping.insert(pair<int,int>(cc->value.val[0],i));
  25. }
  26. cvShowImage("segementation",dst);
  27. waitKey();
  28. cvReleaseMemStorage(&storage);
  29. }
from: http://blog.csdn.net/abcjennifer/article/details/18215953

opencv 金字塔图像分割相关推荐

  1. Python 计算机视觉(十二)—— OpenCV 进行图像分割

    参考的一些文章以及论文我都会给大家分享出来 -- 链接就贴在原文,论文我上传到资源中去,大家可以免费下载学习,如果当天资源区找不到论文,那就等等,可能正在审核,审核完后就可以下载了.大家一起学习,一起 ...

  2. OpenCV各向异性图像分割anisotropic image segmentation的实例(附完整代码)

    OpenCV各向异性图像分割anisotropic image segmentation的实例 OpenCV各向异性图像分割anisotropic image segmentation的实例 Open ...

  3. OpenCV-Python实战(9)——OpenCV用于图像分割的阈值技术

    OpenCV-Python实战(9)--OpenCV用于图像分割的阈值技术 0. 前言 1. 阈值技术简介 2. 简单的阈值技术 2.1 阈值类型 2.2 简单阈值技术的实际应用 3. 自适应阈值算法 ...

  4. opencv 彩色图像分割(inrange)

    opencv 彩色图像分割(inrange) 原文地址: https://www.cnblogs.com/chenzhefan/p/7648433.html 灰度图像大多通过算子寻找边缘和区域生长融合 ...

  5. opencv图像分割合成_opencv 金字塔图像分割

    我所知的opencv中分割函数:watershed(只是看看效果,不能返回每类pixel类属),cvsegmentImage,cvPyrSegmentation(返回pixel类属) 金字塔分割原理篇 ...

  6. android opencv中图像分割,opencv在android平台下的开发【4】-图像滤波详解

    前言 在上一篇opencv-android-图像平滑处理文章中,简单介绍了几种图像平滑,也就是图像模糊的方法,使用了几个简单的滤波器,这都属于图像的滤波操作. opencv针对图像的处理提供了imgp ...

  7. 基于OpenCV的图像分割处理!

    ↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale干货 作者:姚童,Datawhale优秀学习者,华北电力大学 图像阈值化分割是 ...

  8. 基于 OpenCV 的图像分割项目实战

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本期我们将一起来实现一个有趣的问题 -图像分割的算法. 本文的示例 ...

  9. OpenCv 金字塔之上采样与下采样

    常见两类图像金字塔 高斯金字塔 ( Gaussian pyramid): 用来向下/降采样,主要的图像金字塔 拉普拉斯金字塔(Laplacian pyramid): 用来从金字塔低层图像重建上层未采样 ...

最新文章

  1. 文本处理三驾马车 • grep • sed • awk
  2. UIScollerViewUIPageControl的一些使用方法
  3. return 函数
  4. Angular应用页面里appId的生成逻辑和位置
  5. 计算机网络数据链路层次学习
  6. 在Centos7上搭建Mysql数据库
  7. php图片处理-补全图片链接,在链接前添加ip或其他路径-在正则匹配到的字符串前添加指定字符串
  8. photoshop cs6视频教程(从入门到精通)
  9. DIY LDAC蓝牙接收器(一)预备篇
  10. 中国移动的垃圾短信屏蔽算法?
  11. 保健用品行业智慧供应链管理系统:高度整合产业链资源,精细化企业供应商管理
  12. 一个简单的税利计算器(网页版)
  13. ArduPilot姿态控制方法解析---(倾转分离)
  14. 加班有多可怕?据统计:程序员平均寿命仅为37.9岁!
  15. 我们、这样子相爱、什么都不计较,多好啊~
  16. Linux 下安装 wowza 服务器
  17. 推荐一个很不错的刷题网站
  18. python逻辑运算符优先级
  19. 通过 pdftoppm 实现PDF转图片
  20. 了解扎克伯格是如何从一个被女友嫌弃太nerd的loser转变成下一个比尔盖茨--《社交网络》影片评论

热门文章

  1. Ubuntu 18.04安装CUDA(版本10.2)和cuDNN
  2. 积分背后的数字货币,你真的会玩吗?
  3. 使用JSON.parse(),JSON.stringify()实现对对象的深拷贝
  4. 信息革命的新世界正在到来,连睡觉都觉得浪费
  5. Google:狡兔三窟
  6. C语言N台服务器通信,使用socket的Linux上的C语言文件传输顺序服务器和客户端示例程序 ....
  7. Linux GCC lib库相互引用,互相依赖(交叉引用)链接解决办法
  8. MySQL-CentOS7通过YUM安装MySQL5.7.29
  9. MyBatis-10MyBatis注解方式之Provider注解
  10. 《数据结构》知识点Day_03