魔棒工具--RegionGrow算法简介
原地址:http://www.cnblogs.com/easymind223/archive/2012/07/04/2576964.html
ps里面的魔棒工具非常好用,是图像处理中非常常用的一个工具,它现在已经是我的c++工具箱中很重要的一员了,我会在以后的时间里把我的工具箱逐渐介绍给大家。

struct Node
{
int x;
int y;
Node* next;
}; void MyTreasureBox::RegionGrow(const IplImage* src, IplImage* dst, int seedx, int seedy, int threshold, bool flag)
{
if(!src || src->nChannels != 1)return ; int width = src->width;
int height = src->height;
int srcwidthstep = src->widthStep;
uchar* img = (uchar*)src->imageData; //成长区域
cvZero(dst); //标记每个像素点是否被计算过
IplImage* M = cvCreateImage(cvSize(width, height), 8, 1);
int Mwidthstep = M->widthStep; cvZero(M);
M->imageData[seedy * Mwidthstep + seedx] = 1; //种子点位置为1,其它位置为0 CvScalar cur = CV_RGB(255,255,255);
cvSet2D(dst, seedy, seedx, cur); //队列的两端
int start = 0;
int end = 1; Node *queue = new Node;
queue->x = seedx;
queue->y = seedy;
queue->next = NULL;
Node *first = queue;
Node *last = queue; while (end - start > 0)
{
int x = first->x;
int y = first->y;
uchar pixel = (uchar)img[y * srcwidthstep + x]; for (int yy = -1; yy<=1; yy++)
{
for (int xx = -1; xx<=1; xx++)
{
if(flag)
if ( abs(yy) && abs(xx))
continue; int cx = x + xx;
int cy = y + yy;
if (cx >= 0 && cx <width && cy >=0 && cy < height)
{
if (abs(img[cy * srcwidthstep + cx] - pixel) <= threshold && M->imageData[cy * Mwidthstep + cx] != 1)
{
Node *node = new Node;
node->x = cx;
node->y = cy;
node->next = NULL; end++;
last->next = node;
last = node; M->imageData[cy * Mwidthstep + cx] = 1; cvSet2D(dst, cy, cx, cur);
}
}
}
}
Node* temp = first;
first = first->next;
delete temp;
start++;
} cvReleaseImage(&M);
}
魔棒工具--RegionGrow算法简介的更多相关文章
- webrtc 的回声抵消(aec、aecm)算法简介(转)
webrtc 的回声抵消(aec.aecm)算法简介 webrtc 的回声抵消(aec.aecm)算法主要包括以下几个重要模块:1.回声时延估计 2.NLMS(归一化最小均方自适应算法) ...
- AES算法简介
AES算法简介 一. AES的结构 1.总体结构 明文分组的长度为128位即16字节,密钥长度可以为16,24或者32字节(128,192,256位).根据密钥的长度,算法被称为AES-128,AES ...
- 排列熵算法简介及c#实现
一. 排列熵算法简介: 排列熵算法(Permutation Entroy)为度量时间序列复杂性的一种方法,算法描述如下: 设一维时间序列: 采用相空间重构延迟坐标法对X中任一元素x(i)进行相空间 ...
- <算法图解>读书笔记:第1章 算法简介
阅读书籍:[美]Aditya Bhargava◎著 袁国忠◎译.人民邮电出版社.<算法图解> 第1章 算法简介 1.2 二分查找 一般而言,对于包含n个元素的列表,用二分查找最多需要\(l ...
- LARS 最小角回归算法简介
最近开始看Elements of Statistical Learning, 今天的内容是线性模型(第三章..这本书东西非常多,不知道何年何月才能读完了),主要是在看变量选择.感觉变量选择这一块领域非 ...
- AI - 机器学习常见算法简介(Common Algorithms)
机器学习常见算法简介 - 原文链接:http://usblogs.pwc.com/emerging-technology/machine-learning-methods-infographic/ 应 ...
- STL所有算法简介 (转) http://www.cnblogs.com/yuehui/archive/2012/06/19/2554300.html
STL所有算法简介 STL中的所有算法(70个) 参考自:http://www.cppblog.com/mzty/archive/2007/03/14/19819.htmlhttp://hi.baid ...
- PageRank 算法简介
有两篇文章一篇讲解(下面copy)< PageRank算法简介及Map-Reduce实现>来源:http://www.cnblogs.com/fengfenggirl/p/pagerank ...
- Gradient Boosting算法简介
最近项目中涉及基于Gradient Boosting Regression 算法拟合时间序列曲线的内容,利用python机器学习包 scikit-learn 中的GradientBoostingReg ...
随机推荐
- c语言数组初始化问题
2147483648字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素. charstr[10]={'I','','a','m','',‘h’,'a','p','p','y'}; 即把10 ...
- 使用回溯法求所有从n个元素中取m个元素的组合
不多说了,直接上代码,代码中有注释,应该不难看懂. #include <stdlib.h> #include <stdio.h> typedef char ELE_TYPE; ...
- C++学习笔记(十二):重载函数
1. 什么是重载函数 假设同一作用域内的几个函数名字同样但形參列表不同.那么这些函数就称之为--重载函数. 比如: void print( const char *cp); void print(co ...
- android随记
[Android]中国大部分城市地区的结构定义与按拼音排序 http://blog.csdn.net/sodino/article/details/6739522
- fcntl()
fcntl() F_GETFL--------------------------------------------- 将文件状态标志作为函数值返回. 文件状态标志: ...
- javascript笔记整理(数据类型强制/隐式转换 )
A.数据类型强制转换 1.转换为数值类型 Number(参数) 把任何的类型转换为数值类型 A.如果是布尔值,false为0,true为1 var a=false;alert(Number(a)); ...
- (step8.2.7)hdu 1517(A Multiplication Game——巴什博弈变形)
题目大意:输入一个整数n.谁先报的数大于n,谁就输了.(初始值p == 1 , 后一个人报的数必须在前一个人报的数的基础上乘上(2 ~ 9)之间的任意一个数) 解题思路:巴什博奕的变形 1) 解题思 ...
- const与define的使用区别
1.const用于类成员变量定义,一旦定义且不能改变其值.define定义全局常量,在任何地方都可以访问. 2.define不能在类中定义而const可以. 3.const不能在条件语句中定义常量 i ...
- [整理]MongoDB 经常使用命令总结
MongoDB 经常使用命令总结 简单的的增删改查数据 在查询结果中指定显示或者不显示某个字段 比如,我们希望在 lessons 集合中查找全部数据,可是不希望在返回结果中包括 slides 字段:由 ...
- leetcode——Search a 2D Matrix 二维有序数组查找(AC)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...