利用最大流标号法求解最大流,详见代码:

Version:未加头尾节点版;

缺点:havn't take nodes' pixels into consideration

[cpp] view plaincopy
  1. /************************************************************************/
  2. /*                                 MaxFlow solve graph cut program                                                            */
  3. /************************************************************************/
  4. /*
  5. File description:
  6. This program for graph cut based on Ford - Fulkerson Algorithm.
  7. Input:
  8. M(edge number) N(node number)
  9. then M lines input 3 parameters each line:
  10. start_point end_point edge_capacity
  11. e.g 5 4 1 4 40 1 2 20 2 4 10 4 3 30 3 2 10
  12. output:
  13. Line 1:maxflow value
  14. Line2:nodes in Class 1
  15. e.g
  16. MAX Flow is 50
  17. nodes in class S: 1 2
  18. =========================================================================
  19. CreateTime:2011-8-8
  20. Author:@Zhang Ruiqing
  21. */
  22. #include<iostream>
  23. #include<queue>
  24. using namespace std;
  25. #define N 250//point
  26. #define M 250*250//edge
  27. #define INF 1000000000
  28. #define min(a,b) a<b?a:b
  29. int pre[N],map[N][N];
  30. int minlen[N];//minlen[i] represents min length from s to i
  31. int pathmin[N];//min flow in this path from i to t
  32. queue<int>Q;
  33. int n,m,s,t;
  34. void init(int s)
  35. {
  36. memset(pre,0,sizeof(pre));
  37. for(int i=0;i<=n;i++)
  38. minlen[i]=pathmin[i]=INF;
  39. minlen[s]=0;
  40. }
  41. bool bfs(int s,int t)
  42. {
  43. init(s);
  44. //push start node
  45. Q.push(s);
  46. while(!Q.empty())
  47. {
  48. int now=Q.front();
  49. Q.pop();
  50. for(int i=1;i<=n;i++)
  51. {
  52. if(map[now][i]!=0&&minlen[now]+map[now][i]<minlen[i])
  53. {
  54. minlen[i]=minlen[now]+map[now][i];
  55. pre[i]=now;
  56. pathmin[i]=min(pathmin[now],map[now][i]);
  57. Q.push(i);
  58. }
  59. }
  60. }
  61. if(minlen[n]==INF)
  62. return false;
  63. return true;
  64. }
  65. int max_flow(int s,int t)
  66. {
  67. int res=0;
  68. while(bfs(s,t))//if can find an augment road
  69. {
  70. int minflow=pathmin[n];//minimal flow in the path
  71. int point=t;//calculate from end point t to start point s
  72. while(point!=s)
  73. {
  74. int prep=pre[point];
  75. map[prep][point]-=minflow;//positive road -= flow
  76. map[point][prep]+=minflow;//nagative road+= flow
  77. point=prep;
  78. }
  79. res+=minflow;
  80. }
  81. return res;
  82. }
  83. int main()
  84. {
  85. int i,j;
  86. int a,b,c;
  87. while(scanf("%d%d",&m,&n)!=EOF)
  88. {
  89. memset(map,0,sizeof(map));
  90. for(i=0;i<m;i++)
  91. {
  92. cin>>a>>b>>c;
  93. map[a][b]+=c;
  94. }
  95. s=1;
  96. t=n;
  97. cout<<"MAX Flow is "<<max_flow(s,t)<<endl;
  98. cout<<"nodes in class S: 1 ";
  99. for(i=0;i<n;i++)
  100. {
  101. if(pathmin[i]!=INF)
  102. cout<<i<<" ";
  103. }
  104. cout<<endl;
  105. }
  106. return 0;
  107. }

图割Graph-Cut的最大流实现相关推荐

  1. 实战|基于图割算法的木材表面缺陷图像分析

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|新机器视觉 鉴于图割方法的明显优势,白雪冰及其团队采用G ...

  2. 项目实战 基于图割算法的木材表面缺陷图像分析

    鉴于图割方法的明显优势,白雪冰及其团队采用Graph Cuts算法和Grab Cut算法分别对木材表面的单目标和多目标缺陷图像进行分割试验,以总结传统图割方法的不足和改进算法的优点. 针对传统Grap ...

  3. 图像分割之(二)Graph Cut(图割)

    上一文对主要的分割方法做了一个概述.那下面我们对其中几个比较感兴趣的算法做个学习.下面主要是Graph Cut,下一个博文我们再学习下Grab Cut,两者都是基于图论的分割方法.另外OpenCV实现 ...

  4. Graph Cut(图割算法)

    转载自:http://blog.csdn.net/zouxy09/article/details/8532111 Graph cuts是一种十分有用和流行的能量优化算法,在计算机视觉领域普遍应用于前背 ...

  5. 【图割】最大流/最小割算法详解(Yuri Boykov and Vladimir Kolmogorov,2004 )

    本博客主要翻译了Yuri Boykov and Vladimir Kolmogorov在2004年发表的改进最大流最小割算法用于计算机视觉的论文:An Experimental Comparison ...

  6. 图割论文阅读笔记:“GrabCut” — Interactive Foreground Extraction using Iterated Graph Cuts

    "GrabCut" - Interactive Foreground Extraction using Iterated Graph Cuts 摘要 经典的图像分割使用纹理(颜色) ...

  7. Graph Cut and Its Application in Computer Vision

    Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...

  8. matlab实现图割算法中的最大流最小割Max-flow/min-cut问题(一)

    转载自:http://blog.csdn.net/on2way/article/details/43276155 本篇主要介绍matlab实现Max-flow/min-cut的方法,介绍一种只实现了M ...

  9. 最小割(min cut)算法

    0引言 图像分割可以看作不同的划分问题,而图可以进行不同的划分,将图像映射为图后,分割问题就可以用图论方法(如:最小割)求解.这只是直观地解释,具体如何将图像分割转化为求图的最小割呢?本文的分析思路是 ...

最新文章

  1. yii2 获取同一个账号登录的所有session_前端登录方案?这一篇就够了
  2. 数据结构 树的遍历(递归遍历)
  3. 【机器学习】集成学习ensemble之随机森林
  4. MMORPG大型游戏设计与开发(part5 of net)
  5. Dialog高仿Toast实现
  6. mysql auto_inc_MySQL innodb_autoinc_lock_mode 详解
  7. 手把手教你强化学习 (六) 强化学习中的无模型预测
  8. 微信浏览器ISO系统底部导航栏
  9. 微软更新服务器ip地址,微软承认Windows 10更新导致路由等本地IP地址打不开
  10. c语言关系运算符号比较大小,有哪些c语言关系运算符号
  11. python结构体_python中定义结构体
  12. Git 基础知识 - 查看提交历史记录
  13. tbc新服务器没消息,暴雪蓝贴官宣TBC怀旧服2021年内上线,所有服务器直升70级
  14. 2019 acm-icpc 西安全国邀请赛 J
  15. OKR是上下同欲的载体
  16. 东方博宜OJ 1056 - 【入门】所有不超过1000的数中含有数字3的自然数
  17. RoI Pooling详解
  18. 微信小程序,图像识别源码
  19. 文献阅读(2):王昊奋:大规模知识图谱技术
  20. web前端开发相关网站

热门文章

  1. linux如何调试脚本程序,调试Linux shell脚本的方法
  2. 浮点数不能全等比较吗php,php的一些易错知识点整理 | 木凡博客
  3. Windows IO 性能简单测试
  4. 微信快速开发框架(五)-- 利用快速开发框架,快速搭建微信浏览博客园首页文章...
  5. 实现自定义扩展点_spring扩展API接口介绍
  6. Linux下ip route、ip rule、iptables的关系(转
  7. 使用GDAL对HDF数据进行校正
  8. GDAL源码剖析(三)之Swig编译和帮助文档生成
  9. oracle支持ipv6,准备现有的网络以支持 IPv6
  10. Kubernetes在游戏业务应用调研