GraphCuts算法解析,Graphcuts算法求最大流,最小割实例
图割论文大合集下载:
http://download.csdn.net/detail/wangyaninglm/8292305
代码:
/* graph.h */
/* Vladimir Kolmogorov (vnk@cs.cornell.edu), 2001. */ /*
This software library is a modification of the maxflow algorithm
described in An Experimental Comparison of Min-Cut/Max-Flow Algorithms
for Energy Minimization in Computer Vision.
Yuri Boykov and Vladimir Kolmogorov.
In Third International Workshop on Energy Minimization
Methods in Computer Vision and Pattern Recognition, September 2001 This algorithm was originally developed at Siemens.
The main modification is that two trees are used for finding
augmenting paths - one grows from the source and the other
from the sink. (The original algorithm used only the former one).
Details will be described in my PhD thesis. This implementation uses an adjacency list graph representation.邻接链表
Memory allocation:
Nodes: 22 bytes + one field to hold a residual capacity
of t-links (by default it is 'short' - 2 bytes)
Arcs: 12 bytes + one field to hold a residual capacity 剩余容量
(by default it is 'short' - 2 bytes)
(Note that arcs are always added in pairs (弧都是成对的添加)- in forward and reverse directions) Example usage (computes a maxflow on the following graph): SOURCE
/ \
1/ \2
/ 3 \
node0 -----> node1
| <----- |
| 4 |
\ /
5\ /6
\ /
SINK /////////////////////////////////////////////////// #include <stdio.h>
#include "graph.h" void test_maxflow()
{
Graph::node_id nodes[2];
Graph *g = new Graph(); nodes[0] = g -> add_node();
nodes[1] = g -> add_node();
g -> set_tweights(nodes[0], 1, 5);
g -> set_tweights(nodes[1], 2, 6);
g -> add_edge(nodes[0], nodes[1], 3, 4); Graph::flowtype flow = g -> maxflow(); printf("Flow = %d\n", flow);
printf("Minimum cut:\n");
if (g->what_segment(nodes[0]) == Graph::SOURCE)
printf("node0 is in the SOURCE set\n");
else
printf("node0 is in the SINK set\n");
if (g->what_segment(nodes[1]) == Graph::SOURCE)
printf("node1 is in the SOURCE set\n");
else
printf("node1 is in the SINK set\n"); delete g;
} ///////////////////////////////////////////////////
*/
void test_maxflow()
{
Graph::node_id nodes[2];
Graph *g = new Graph(); nodes[0] = g -> add_node();
nodes[1] = g -> add_node();
g -> set_tweights(nodes[0], 3, 3);
g -> set_tweights(nodes[1], 3, 1);
g -> add_edge(nodes[0], nodes[1], 1, 0); Graph::flowtype flow = g -> maxflow(); printf("Flow = %d\n", flow);
printf("Minimum cut:\n");
if (g->what_segment(nodes[0]) == Graph::SOURCE)
printf("node0 is in the SOURCE set\n");
else
printf("node0 is in the SINK set\n");
if (g->what_segment(nodes[1]) == Graph::SOURCE)
printf("node1 is in the SOURCE set\n");
else
printf("node1 is in the SINK set\n"); delete g;
}
这块主要就是要理解,什么是maxflow,以及节点最后分割的类型是SOURCE还是SINK分别意味着什么
graphcuts算法时间复杂度与其他最大流算法的比较:
添加几篇文章地址:
graphcuts资料博客大合集
http://vision.csd.uwo.ca/code/
http://lincccc.blogspot.tw/2011/04/graph-cut-and-its-application-in.html
http://blog.csdn.net/zouxy09/article/details/8532106
http://lincccc.blogspot.tw/2011/03/cuda-cuts-fast-graph-cuts-on-gpu_03.html
http://blog.csdn.net/hebby06/article/details/5341228
GraphCuts算法解析,Graphcuts算法求最大流,最小割实例的更多相关文章
- 最大流&最小割 - 专题练习
[例1][hdu5889] - 算法结合(BFS+Dinic) 题意 \(N\)个点\(M\)条路径,每条路径长度为\(1\),敌人从\(M\)节点点要进攻\(1\)节点,敌人总是选择最优路径即最短路 ...
- 最大流-最小割 MAXFLOW-MINCUT ISAP
简单的叙述就不必了. 对于一个图,我们要找最大流,对于基于增广路径的算法,首先必须要建立反向边. 反向边的正确性: 我努力查找了许多资料,都没有找到理论上关于反向边正确性的证明. 但事实上,我们不难理 ...
- 网络流 最大流—最小割 之SAP算法 详解
首先引入几个新名词: 1.距离标号: 所谓距离标号 ,就是某个点到汇点的最少的弧的数量(即边权值为1时某个点到汇点的最短路径长度). 设点i的标号为level[i],那么如果将满足level[i]=l ...
- 【UVA1515 算法竞赛入门指南】 水塘【最小割】
题意: 输入一个h行w列的字符矩阵,草地用“#”表示,洞用"."表示.你可以把草改成洞,每格花费为d,也可以把洞填上草,每格花费为f.最后还需要在草和洞之间修围栏,每条边花费为b. ...
- matlab练习程序(最大流/最小割)
学习这个算法是为学习图像处理中的图割算法做准备的. 基本概念: 1.最大流是一个有向图. 2.一个流是最大流,当且仅当它的残余网络中不包括增广路径. 3.最小割就是网络中所有割中值最小的那个割,最小割 ...
- 「网络流24题」「LuoguP2774」方格取数问题(最大流 最小割
Description 在一个有 m*n 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意 2 个数所在方格没有公共边,且取出的数的总和最大.试设计一个满足要求的取数算法.对于给定的方 ...
- UVa11248 Frequency Hopping(最大流+最小割)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33206 [思路] 最大流最小割. 可以确定的是如果不可行需要修改的 ...
- HDU6582 Path【优先队列优化最短路 + dinic最大流 == 最小割】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 来源:2019 Multi-University Training Contest 1 题目大意 ...
- 最大流&最小割&费用流模版
好久都没有搞博客了.想认真写又要准备文化课期末了. ISAP 流程: 原理就是dfs找增广路. 最基础的建反向边以便反悔就不说了. 但是记录一个dep(dis)表示层数,一开始BFS(从t开始,dis ...
随机推荐
- 安卓Button-TextView-EditText综合运用
1.如何使用安卓中的按键Button? 1.先从控件库拖一个按钮button的控件,在XML设置好宽高等参数 对应的就是Button这个图标,直接拖出来即可; 以下是设置这个按钮对应的XML代码: & ...
- 利用CocoaHTTPServer实现wifi局域网传输文件到iphone
背景 近日在做一个代码阅读器,其中涉及到代码文件的上传,之前看到过许多app支持局域网传文件,因此就通过查询和研究实现了此功能,我是用的框架是CocoaHTTPServer. 原理 CocoaHTTP ...
- EBS库存(INV)模块常用表
select * from org_organization_definitions库存组织 select * from mtl_parameters组织参数 select * from mtl ...
- 2.3、Android Studio使用Layout Editor设计UI
Android Studio提供了一个高级的布局编辑器,允许你拖拽控件,在编辑XML之后可以实时预览. 在布局编辑器中,你在文字视图和设计视图直接来回切换. 在文字视图中编辑 你可以在文字视图中编辑你 ...
- Runtime系列(二)--Runtime的使用场景
Runtime 理解介绍的文章非常多,我只想讲讲Runtime 可以用在哪里,而我在项目里哪些地方用到了runtime.多以实际使用过程为主,来介绍runtime的使用. * 那么runtime 怎么 ...
- 【IOS 开发】Objective-C Foundation 框架 -- 字符串 | 日期 | 对象复制 | NSArray | NSSet | NSDictionary | 谓词
一. 字符串 API 1. NSString 用法简介 (1) NSString API 介绍 NSString 功能 : -- 创建字符串 : 使用 init 开头的实例方法, 也可以使用 Stri ...
- android之View绘制
Android系统的视图结构的设计也采用了组合模式,即View作为所有图形的基类,Viewgroup对View继承扩展为视图容器类,由此就得到了视图部分的基本结构--树形结构 View定义了绘图的基本 ...
- 运用 三种 原生 谷歌 阿里 解析和生成json
三种类生成JSON数据方法 JSON(原生): 第一种 JSONStringer和JSONObject区别在于添加对象时是按顺序添加的比如说 JSONStringer 添加 a:1 b:2 c:3那么 ...
- J2EE进阶(十一)SSH框架整合常见问题汇总(二)
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of cn. ...
- Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(四)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 现在打开MainScene.m文件,首先设置实例变量: @imp ...