Understanding of Mincut algorithm in graph model

Source: Internet
Author: User

It is one of the most popular algorithms to use graph segmentation algorithm to segment images. When the image is segmented by this method, the corresponding energy function should be searched with minimum value, and when the energy function belongs to the convex function in the domain of definition, the unique extremum solution can be obtained by using the gradient descent method, em and other classical algorithms, and the solution is the global minimum solution. But for the energy function is not convex function in the definition domain, it is easy to get into the local minima problem by using the above classical algorithm, so it is difficult to obtain the ideal effect. Although the use of simulated annealing method can reduce the probability of falling into local minima, but this is not the optimal solution.

Using graph model to solve the problem of energy function optimal solution brings a new way, and the mincut algorithm is an effective method to solve the graph model. The following is an intuitive introduction to the mincut algorithm what is the ultimate goal? What is the basic idea of a solution algorithm Max-flow? and gives an example of a mincut algorithm

the ultimate goal of the mincut algorithm is to solve the energy function problem

using the energy function to construct the equivalent graph model structure, the optimal solution of the energy function is transformed into an equivalent intuitionistic graph model segmentation problem. Mincut algorithm is the method of dividing graph model, and the optimal solution of energy function is obtained. The relationship between energy function and graph model is described below. Assuming the following energy function, the first item on the right is a single-node potential energy function, and the second is a potential energy function between nodes, in this case x is the value in {0,1}. The problem to solve is how to assign a value of n x to minimize the energy function.


The following is an example graph of the graph model and its segmentation, with the weights between the gray nodes on the S-node and the LAMBDA,T nodes and the gray nodes on the surface of the-lambda, and the weights between the plane gray nodes are beta. The segmentation result of right Green line is obtained by mincut algorithm. The result shows that the gray nodes of P and Q over the Green Line are attributed to S and the other side to T, so that the result of the segmentation is the minimization of the weights between the elements {s} and {T}, that is, the energy of the corresponding target energy function is minimized. The concrete process finally gives a concrete implementation example, here the explanation can see the literature "Exact maximum a posteriori estimation for binary images" This document is the first to propose the use of graph model to solve the problem of energy function optimization.


Basic idea of Max-flow algorithm

from the max-flow literal meaning can be seen that the algorithm and traffic has a relationship, the following is a description of the basic idea of the algorithm an example diagram. Consider S as a water source, T is the source of the water, the middle edge is a series of pipelines, the maximum flow of the pipeline by the edge above the data (x, y) in the X., Y represents the actual flow of each pipe when the piping system reaches the maximum flow. For example, the maximum pipe flow between V0 and V3 is 5, and when the piping system reaches the maximum flow, the actual flow of the pipe is 4. As can be seen from the diagram, when the pipe system reached the maximum flow, a total of 3 pipe flow reached full load state, the 3 pipes are s->v0,s->v1,v2->v5 these 3 pipes determine the graph model of the segmentation results, the results as shown in the way dashed line. The minimum value corresponding to the energy function when the system reaches the maximum flow is the equivalence relation and is not contradictory.


An example of a mincut algorithm

Here is a 2*2 diagram model, using the mincut algorithm to split it, the source code of the algorithm can be downloaded on the site http://pub.ist.ac.at/~vnk/software.html.

Add_edge (node_id _i, node_id _j, Captype cap, Captype rev_cap)
The function defines the weights between the nodes I and J, the CAP is the weight of the i->j, andtheRev_cap is the weight of the j->i. This one is in the direction.

Add_tweights (node_id I, Tcaptype cap_source, Tcaptype cap_sink)
This function defines the weights between the nodes I and S, T,Cap_source is the weight of I and S , Cap_sink is the weight of I and T. This has no direction.

The following is a description of the entire graph model code running results shown, the results show that the node 0,1 attributed to the T set, node 2,3 attributed to the s set, and shows that the current system maximum flow of 8.


The specific process of the above analysis is as follows:

Now there are {2,3,s}, {0,1,t} These two categories are derived {2,3,s}->{0,1,t} weight and the process, the weight sum only calculate the case of edge joins, such as S->t does not exist edge so do not calculate the weight of both.

s to 0 and 1 weights and for 1+3=4;the weights of 2 to 1 and T are 1+1=2, because 2 and 3 are not adjacent so there is no weight or weight of 0;3 to 0 and T weights and for 1+1=2;c=4+2+2=8;if another method of segmentation: 0 belongs to s,1,2,3 belongs to T at this time of the c=18, than the ideal segmentation method is larger, this method although the C value is large but the actual flow is not so large, because the pipe from the three-way to T can not achieve such a large flow of traffic. s to 3+5+4=12 weights and for the;0 to 1,3,t weights and for 1+1+4=6;c=12+6=18;

int main () {typedef graph<int,int,int> graphtype; Graphtype *g = new Graphtype (/*estimated # of nodes*/2,/*estimated # of edges*/1); G-Add_node (); G-Add_node (); G-Add_node (); G-Add_node ();  G-add_tweights (0,/* capacities */1, 4);//indicates that nodes 0 and s have a weight of 1, and the weights for nodes 0 and T are 4 G, add_tweights (1,/* capacities */ 3, 4); G-Add_tweights (2,/* capacities */5, 1); G-Add_tweights (3,/* capacities */4, 1); G-Add_edge (0, 1,/* capacities */1, 1);//indicates that the weight of the node 0->1 is 1,<span style= "line-height:1.5; Font-family:simsun; " > indicates that the weight of the node 1->0 is 1</span> g, Add_edge (1, 2,/* capacities */1, 1); G-Add_edge (2, 3,/* capacities */1, 1); G-Add_edge (3, 0,/* capacities */1, 1); int flow = G-Maxflow (); printf ("flow =%d\n", flow); printf ("Minimum cut:\n"); if (g->what_segment (0) = = Graphtype::source) printf ("Node0 is in the SOURCE set\n"); else printf ("Node0 is in the SINK set\n"); if (g>what_segment (1) = = Graphtype::source) printf ("Node1 is in the SOURCE set\n"); else printf ("Node1 is in the SINK set\n"); if (g->what_segment (2) = = Graphtype::source) printf ("Node2 is in the SOURCE set\n"); else printf ("Node2 is in the SINK set\n"); if (g->what_segment (3) = = Graphtype::source) printf ("Node3 is in the SOURCE set\n"); else printf ("Node3 is in the SINK set\n"); Delete g; System ("pause"); return 0;}








Understanding of Mincut algorithm in graph model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.