OpenCv 027---均值迁移滤波
时间:2019-11-13
本文章向大家介绍OpenCv 027---均值迁移滤波,主要包括OpenCv 027---均值迁移滤波使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
1 前备知识
均值迁移模糊是图像边缘保留滤波算法中的一种,经常用在对图像进行分水岭分割之前去噪声,可以大幅度提升分水岭分割的效果。均值迁移模糊的主要思想如下: 就是在图像进行开窗的时候,考虑像素值空间范围分布,只有符合分布的像素点才参与计算,计算得到像素均值与空间位置均值,使用新的均值位置作为窗口中心位置继续基于给定像素值空间分布计算均值与均值位置,如此不断迁移中心位置直到不再变化位置(dx=dy=0),但是在实际情况中我们会人为设置一个停止条件比如迁移几次,这样就可以把最后的RGB均值赋值给中心位置。
2 所用到的主要OpenCv API
/** @brief Performs initial step of meanshift segmentation of an image. The function implements the filtering stage of meanshift segmentation, that is, the output of the function is the filtered "posterized" image with color gradients and fine-grain texture flattened. At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is considered: \f[(x,y): X- \texttt{sp} \le x \le X+ \texttt{sp} , Y- \texttt{sp} \le y \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)|| \le \texttt{sr}\f] where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively (though, the algorithm does not depend on the color space used, so any 3-component color space can be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector (R',G',B') are found and they act as the neighborhood center on the next iteration: \f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f] After the iterations over, the color components of the initial pixel (that is, the pixel from where the iterations started) are set to the final value (average color at the last iteration): \f[I(X,Y) <- (R*,G*,B*)\f] When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is run on the smallest layer first. After that, the results are propagated to the larger layer and the iterations are run again only on those pixels where the layer colors differ by more than sr from the lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the results will be actually different from the ones obtained by running the meanshift procedure on the whole original image (i.e. when maxLevel==0). @param src The source 8-bit, 3-channel image. @param dst The destination image of the same format and the same size as the source. @param sp The spatial window radius. @param sr The color window radius. @param maxLevel Maximum level of the pyramid for the segmentation. @param termcrit Termination criteria: when to stop meanshift iterations. */ CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, double sp, double sr, int maxLevel = 1, TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) );
3 程序代码
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int artc, char** argv) { Mat src = imread("images/Demo.jpg"); if (src.empty()) { printf("could not load image...\n"); return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input", src); Mat dst; pyrMeanShiftFiltering(src, dst, 15, 50, 1, TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 5, 1)); imshow("result", dst); waitKey(0); return 0; }
4 运行结果
略
5 扩展及注意事项
none
6*目前只做大概了解,知道有这一算法,后续具体使用再做具体分析
后面发现对着知识星球上的过程看倒不如直接看书.....
所以现在写这些东西只是把它当成一种养成,只做很简单的了解,贴下API,浅入浅出,让自己知道有这么一回事....
回归课本,按照课本内容来会更高效一些,而且知识点也较全,看完课本再回过头将一些知识点往对应的博文上添加
原文地址:https://www.cnblogs.com/Vince-Wu/p/11847095.html
- 这是一个悲伤的故事
- Golang语言社区--标准库分析之strconv包
- Golang语言社区--结构体数据排序
- mybatis-plus思维导图,让mybatis-plus不再难懂
- ABAP OPEN SQL里OPEN CURSOR和SELECT的比较
- 如何用ABAP代码读取CDS view association的数据
- 使用代币替代传统积分系统
- BTA 常问的 Java基础40道常见面试题及详细答案
- Docker PHP 最佳实践
- 颠覆你对区块链的认识
- 三种决策树算法(ID3, CART, C4.5)及Python实现
- PHP入门-常量基本规则
- PHP入门-书写语法以及基本规范
- 如何清除浮动
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法