opencv 金字塔图像分割
我所知的opencv中分割函数:watershed(只是看看效果,不能返回每类pixel类属),cvsegmentImage,cvPyrSegmentation(返回pixel类属)
金字塔分割原理篇在这里,本文只提供代码。
Segment函数:
- #include<cv.h>
- #include <cvaux.h>
- #include <opencv\cxcore.hpp>
- #include <opencv.hpp>
- #include <nonfree.hpp>
- #include <core/core.hpp>
- #include <imgproc/imgproc.hpp>
- #include <imgproc/imgproc_c.h>
- #include <vector>
- #include <map>
- #include <highgui.h>
- using namespace std;
- using namespace cv;
- void Segment(IplImage* I)
- {
- parameters initialization//
- int mode = CV_RETR_LIST;
- int level = 2, block_size = 1000;
- CvMemStorage* storage = cvCreateMemStorage(block_size);
- CvSeq* components;
- double threshold1 = 100,threshold2 = 50;
- IplImage *src = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,1);
- cvCvtColor(I,src,CV_RGB2GRAY);
- IplImage* dst = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,1);
- src->width = dst->width = (I->width & -(1 << level));
- src->height = dst->height = (I->height & -(1 << level));
- //Segment/
- cvPyrSegmentation(src,dst,storage,&components,level,threshold1,threshold2);
- int ncomp = components->total;
- cout<<"segemented into "<<ncomp<<" components."<<endl;
- //Get Components/
- map<int, int>mapping;//map color value to component id (classify)
- for (int i = 0; i<ncomp; i++)//foreach connection component
- {
- CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(components,i);
- 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));
- mapping.insert(pair<int,int>(cc->value.val[0],i));
- }
- cvShowImage("segementation",dst);
- waitKey();
- cvReleaseMemStorage(&storage);
- }
彩色图分割版本:
- void Segment(IplImage* I)
- {
- parameters initialization//
- int mode = CV_RETR_LIST;
- int level = 2, block_size = 1000;
- CvMemStorage* storage = cvCreateMemStorage(block_size);
- CvSeq* components;
- double threshold1 = 10,threshold2 = 50;
- IplImage *src = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,3);
- src = cvCloneImage(I);
- IplImage* dst = cvCreateImage(cvGetSize(I),IPL_DEPTH_8U,3);
- src->width = dst->width = (I->width & -(1 << level));
- src->height = dst->height = (I->height & -(1 << level));
- //Segment/
- cvPyrSegmentation(src,dst,storage,&components,level,threshold1,threshold2);
- int ncomp = components->total;
- cout<<"segemented into "<<ncomp<<" components."<<endl;
- //Get Components/
- map<int, int>mapping;//map color value to component id (classify)
- for (int i = 0; i<ncomp; i++)//foreach connection component
- {
- CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(components,i);
- 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));
- mapping.insert(pair<int,int>(cc->value.val[0],i));
- }
- cvShowImage("segementation",dst);
- waitKey();
- cvReleaseMemStorage(&storage);
- }
opencv 金字塔图像分割相关推荐
- Python 计算机视觉(十二)—— OpenCV 进行图像分割
参考的一些文章以及论文我都会给大家分享出来 -- 链接就贴在原文,论文我上传到资源中去,大家可以免费下载学习,如果当天资源区找不到论文,那就等等,可能正在审核,审核完后就可以下载了.大家一起学习,一起 ...
- OpenCV各向异性图像分割anisotropic image segmentation的实例(附完整代码)
OpenCV各向异性图像分割anisotropic image segmentation的实例 OpenCV各向异性图像分割anisotropic image segmentation的实例 Open ...
- OpenCV-Python实战(9)——OpenCV用于图像分割的阈值技术
OpenCV-Python实战(9)--OpenCV用于图像分割的阈值技术 0. 前言 1. 阈值技术简介 2. 简单的阈值技术 2.1 阈值类型 2.2 简单阈值技术的实际应用 3. 自适应阈值算法 ...
- opencv 彩色图像分割(inrange)
opencv 彩色图像分割(inrange) 原文地址: https://www.cnblogs.com/chenzhefan/p/7648433.html 灰度图像大多通过算子寻找边缘和区域生长融合 ...
- opencv图像分割合成_opencv 金字塔图像分割
我所知的opencv中分割函数:watershed(只是看看效果,不能返回每类pixel类属),cvsegmentImage,cvPyrSegmentation(返回pixel类属) 金字塔分割原理篇 ...
- android opencv中图像分割,opencv在android平台下的开发【4】-图像滤波详解
前言 在上一篇opencv-android-图像平滑处理文章中,简单介绍了几种图像平滑,也就是图像模糊的方法,使用了几个简单的滤波器,这都属于图像的滤波操作. opencv针对图像的处理提供了imgp ...
- 基于OpenCV的图像分割处理!
↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale干货 作者:姚童,Datawhale优秀学习者,华北电力大学 图像阈值化分割是 ...
- 基于 OpenCV 的图像分割项目实战
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本期我们将一起来实现一个有趣的问题 -图像分割的算法. 本文的示例 ...
- OpenCv 金字塔之上采样与下采样
常见两类图像金字塔 高斯金字塔 ( Gaussian pyramid): 用来向下/降采样,主要的图像金字塔 拉普拉斯金字塔(Laplacian pyramid): 用来从金字塔低层图像重建上层未采样 ...
最新文章
- 文本处理三驾马车 • grep • sed • awk
- UIScollerViewUIPageControl的一些使用方法
- return 函数
- Angular应用页面里appId的生成逻辑和位置
- 计算机网络数据链路层次学习
- 在Centos7上搭建Mysql数据库
- php图片处理-补全图片链接,在链接前添加ip或其他路径-在正则匹配到的字符串前添加指定字符串
- photoshop cs6视频教程(从入门到精通)
- DIY LDAC蓝牙接收器(一)预备篇
- 中国移动的垃圾短信屏蔽算法?
- 保健用品行业智慧供应链管理系统:高度整合产业链资源,精细化企业供应商管理
- 一个简单的税利计算器(网页版)
- ArduPilot姿态控制方法解析---(倾转分离)
- 加班有多可怕?据统计:程序员平均寿命仅为37.9岁!
- 我们、这样子相爱、什么都不计较,多好啊~
- Linux 下安装 wowza 服务器
- 推荐一个很不错的刷题网站
- python逻辑运算符优先级
- 通过 pdftoppm 实现PDF转图片
- 了解扎克伯格是如何从一个被女友嫌弃太nerd的loser转变成下一个比尔盖茨--《社交网络》影片评论
热门文章
- Ubuntu 18.04安装CUDA(版本10.2)和cuDNN
- 积分背后的数字货币,你真的会玩吗?
- 使用JSON.parse(),JSON.stringify()实现对对象的深拷贝
- 信息革命的新世界正在到来,连睡觉都觉得浪费
- Google:狡兔三窟
- C语言N台服务器通信,使用socket的Linux上的C语言文件传输顺序服务器和客户端示例程序 ....
- Linux GCC lib库相互引用,互相依赖(交叉引用)链接解决办法
- MySQL-CentOS7通过YUM安装MySQL5.7.29
- MyBatis-10MyBatis注解方式之Provider注解
- 《数据结构》知识点Day_03