图割Graph-Cut的最大流实现
利用最大流标号法求解最大流,详见代码:
Version:未加头尾节点版;
缺点:havn't take nodes' pixels into consideration
- /************************************************************************/
- /* MaxFlow solve graph cut program */
- /************************************************************************/
- /*
- File description:
- This program for graph cut based on Ford - Fulkerson Algorithm.
- Input:
- M(edge number) N(node number)
- then M lines input 3 parameters each line:
- start_point end_point edge_capacity
- e.g 5 4 1 4 40 1 2 20 2 4 10 4 3 30 3 2 10
- output:
- Line 1:maxflow value
- Line2:nodes in Class 1
- e.g
- MAX Flow is 50
- nodes in class S: 1 2
- =========================================================================
- CreateTime:2011-8-8
- Author:@Zhang Ruiqing
- */
- #include<iostream>
- #include<queue>
- using namespace std;
- #define N 250//point
- #define M 250*250//edge
- #define INF 1000000000
- #define min(a,b) a<b?a:b
- int pre[N],map[N][N];
- int minlen[N];//minlen[i] represents min length from s to i
- int pathmin[N];//min flow in this path from i to t
- queue<int>Q;
- int n,m,s,t;
- void init(int s)
- {
- memset(pre,0,sizeof(pre));
- for(int i=0;i<=n;i++)
- minlen[i]=pathmin[i]=INF;
- minlen[s]=0;
- }
- bool bfs(int s,int t)
- {
- init(s);
- //push start node
- Q.push(s);
- while(!Q.empty())
- {
- int now=Q.front();
- Q.pop();
- for(int i=1;i<=n;i++)
- {
- if(map[now][i]!=0&&minlen[now]+map[now][i]<minlen[i])
- {
- minlen[i]=minlen[now]+map[now][i];
- pre[i]=now;
- pathmin[i]=min(pathmin[now],map[now][i]);
- Q.push(i);
- }
- }
- }
- if(minlen[n]==INF)
- return false;
- return true;
- }
- int max_flow(int s,int t)
- {
- int res=0;
- while(bfs(s,t))//if can find an augment road
- {
- int minflow=pathmin[n];//minimal flow in the path
- int point=t;//calculate from end point t to start point s
- while(point!=s)
- {
- int prep=pre[point];
- map[prep][point]-=minflow;//positive road -= flow
- map[point][prep]+=minflow;//nagative road+= flow
- point=prep;
- }
- res+=minflow;
- }
- return res;
- }
- int main()
- {
- int i,j;
- int a,b,c;
- while(scanf("%d%d",&m,&n)!=EOF)
- {
- memset(map,0,sizeof(map));
- for(i=0;i<m;i++)
- {
- cin>>a>>b>>c;
- map[a][b]+=c;
- }
- s=1;
- t=n;
- cout<<"MAX Flow is "<<max_flow(s,t)<<endl;
- cout<<"nodes in class S: 1 ";
- for(i=0;i<n;i++)
- {
- if(pathmin[i]!=INF)
- cout<<i<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
图割Graph-Cut的最大流实现相关推荐
- 实战|基于图割算法的木材表面缺陷图像分析
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|新机器视觉 鉴于图割方法的明显优势,白雪冰及其团队采用G ...
- 项目实战 基于图割算法的木材表面缺陷图像分析
鉴于图割方法的明显优势,白雪冰及其团队采用Graph Cuts算法和Grab Cut算法分别对木材表面的单目标和多目标缺陷图像进行分割试验,以总结传统图割方法的不足和改进算法的优点. 针对传统Grap ...
- 图像分割之(二)Graph Cut(图割)
上一文对主要的分割方法做了一个概述.那下面我们对其中几个比较感兴趣的算法做个学习.下面主要是Graph Cut,下一个博文我们再学习下Grab Cut,两者都是基于图论的分割方法.另外OpenCV实现 ...
- Graph Cut(图割算法)
转载自:http://blog.csdn.net/zouxy09/article/details/8532111 Graph cuts是一种十分有用和流行的能量优化算法,在计算机视觉领域普遍应用于前背 ...
- 【图割】最大流/最小割算法详解(Yuri Boykov and Vladimir Kolmogorov,2004 )
本博客主要翻译了Yuri Boykov and Vladimir Kolmogorov在2004年发表的改进最大流最小割算法用于计算机视觉的论文:An Experimental Comparison ...
- 图割论文阅读笔记:“GrabCut” — Interactive Foreground Extraction using Iterated Graph Cuts
"GrabCut" - Interactive Foreground Extraction using Iterated Graph Cuts 摘要 经典的图像分割使用纹理(颜色) ...
- Graph Cut and Its Application in Computer Vision
Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...
- matlab实现图割算法中的最大流最小割Max-flow/min-cut问题(一)
转载自:http://blog.csdn.net/on2way/article/details/43276155 本篇主要介绍matlab实现Max-flow/min-cut的方法,介绍一种只实现了M ...
- 最小割(min cut)算法
0引言 图像分割可以看作不同的划分问题,而图可以进行不同的划分,将图像映射为图后,分割问题就可以用图论方法(如:最小割)求解.这只是直观地解释,具体如何将图像分割转化为求图的最小割呢?本文的分析思路是 ...
最新文章
- yii2 获取同一个账号登录的所有session_前端登录方案?这一篇就够了
- 数据结构 树的遍历(递归遍历)
- 【机器学习】集成学习ensemble之随机森林
- MMORPG大型游戏设计与开发(part5 of net)
- Dialog高仿Toast实现
- mysql auto_inc_MySQL innodb_autoinc_lock_mode 详解
- 手把手教你强化学习 (六) 强化学习中的无模型预测
- 微信浏览器ISO系统底部导航栏
- 微软更新服务器ip地址,微软承认Windows 10更新导致路由等本地IP地址打不开
- c语言关系运算符号比较大小,有哪些c语言关系运算符号
- python结构体_python中定义结构体
- Git 基础知识 - 查看提交历史记录
- tbc新服务器没消息,暴雪蓝贴官宣TBC怀旧服2021年内上线,所有服务器直升70级
- 2019 acm-icpc 西安全国邀请赛 J
- OKR是上下同欲的载体
- 东方博宜OJ 1056 - 【入门】所有不超过1000的数中含有数字3的自然数
- RoI Pooling详解
- 微信小程序,图像识别源码
- 文献阅读(2):王昊奋:大规模知识图谱技术
- web前端开发相关网站
热门文章
- linux如何调试脚本程序,调试Linux shell脚本的方法
- 浮点数不能全等比较吗php,php的一些易错知识点整理 | 木凡博客
- Windows IO 性能简单测试
- 微信快速开发框架(五)-- 利用快速开发框架,快速搭建微信浏览博客园首页文章...
- 实现自定义扩展点_spring扩展API接口介绍
- Linux下ip route、ip rule、iptables的关系(转
- 使用GDAL对HDF数据进行校正
- GDAL源码剖析(三)之Swig编译和帮助文档生成
- oracle支持ipv6,准备现有的网络以支持 IPv6
- Kubernetes在游戏业务应用调研