简体   繁体   中英

Algorithm for least cost image segmentation

Im having a hard time trying to figure an algorithm to solve the problem of image segmentation with min-cost. The cost of the image is calculated this way:

The weight of the pixels in the first plan + the weight of the pixels on the second plan + weight of the edges that connect pixels from different plans. (If 2 pixels are on the same plan, we dont count the cost of the edge that connects them)

The input to my problem follows this pattern:

Two Numbers.First number referes to number of lines, second number refers to number of columns

5 5

The weights of the pixels on the first plan(P):

8 7 9 9 7
6 2 2 8 7
9 1 2 1 8
2 1 3 1 7
1 3 2 1 9

The weights of the pixels on the second plan(C):

2 1 2 3 2
1 9 9 1 3
1 7 7 9 3
8 7 9 7 2
7 9 8 9 1

The weights of the edges that connect the pixels horizontally.

8 9 7 6
1 9 0 8
1 8 9 2
8 7 9 1
9 8 7 2

The weight of the edges that connect the pixels vertically.

8 2 1 7 9
7 8 7 1 8
2 8 7 7 8
9 7 8 9 8

The objective is to find the segmentation with the least cost and to return a matrix that shows which pixels belong to the first and second plan.

Output for this case:

57

C C C C C 
C P P C C 
C P P P C 
P P P P C 
P P P P C

Image that represents the problem:

Here is an image that shows why the answer is this:

In my classes my teachers told us that Edmund-Karps will solve this problem but i cant see how to model this problem in one where we are suppoose to find the max flux.

This is a classic max-flow problem. Treat every pixel as a node. Create two new nodes S and T . For every pixel x , add a directed edge (S, x) with cost equal to the weight of x in (P). Similarly, add a directed edge (x, T) with cost equal to the weight of x in (C). Finally, add bidirectional edges between adjacent pixels, using the weights of edges given.

Then, you can show that any S - T cut in this graph corresponds to an image segmentation. In particular, there are 3 kinds of edges in such a cut:

  • Edges between S and a pixel x , which correspond to putting x in plane (P)
  • Edges between a pixel x and T , which correspond to putting x in plane (C)
  • Edges between two pixels x and y , which correspond to edges between planes.

Hence, the min-cut in this graph precisely corresponds to the best image segmentation.

By the min cut max flow theorem, the min cut can be found using a max flow algorithm such as Edmonds-Karp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM