graph-cut算法是基于有向图的一种最优分界线的自动生成算法,常用于前景背景分割,立体视觉,纹理合成及图像拼接等领域。graph-cut算法中要求所处理的图为有向图,可将无向图中正反两个方向都赋予相同的权值即可得到可采用graph-cut算法处理的有向图,其算法流程可以简单表示如
1.Find the path from source to sink
2.While (path exists)
3.flow += maximum capacity in the path
4.Build the residual graph (“subtract” the flow)
5.Find the path in the residual graph
1.Find the path from source to sink
2.While (path exists)
3.flow += maximum capacity in the path
4.Build the residual graph (“subtract” the flow)
5.Find the path in the residual graph
6.End
其中步骤1即为图的遍历;步骤4中的残余图是在沿源点到达汇点的边的权值减去该路径的最大流,同时在其反方向即该路径上从汇点到达源点的路径上边的权值加上该路径的最大流;
当循环结束后图被分割为两部分,一部分是源点可以到达的顶点,另一部分是源点不可到达的顶点,这样就将影像分为了两个部分,其分界处成为cut即分界线。此处将原始图中边的上的权值视为开销的话该算法得到的cut分界线就是使开销最小的全局最优的结果之一(结果并不一定是唯一的)。