[英]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): 第一个计划(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): 第二个平面图(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. 在我的课堂上,我的老师告诉我们,埃德蒙·卡普斯(Edmund-Karps)将解决此问题,但我看不到如何在我们希望找到最大通量的情况下对该问题进行建模。
This is a classic max-flow problem. 这是一个经典的最大流量问题。 Treat every pixel as a node. 将每个像素视为一个节点。 Create two new nodes S
and T
. 创建两个新节点S
和T
For every pixel x
, add a directed edge (S, x)
with cost equal to the weight of x
in (P). 对于每个像素x
,添加成本等于(P)中x
权重的有向边(S, x)
)。 Similarly, add a directed edge (x, T)
with cost equal to the weight of x
in (C). 类似地,添加成本等于(C)中x
权重的有向边(x, T)
)。 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. 然后,您可以证明此图中的任何S
- T
剪切都对应于图像分割。 In particular, there are 3 kinds of edges in such a cut: 特别是,这种切割有3种边缘:
S
and a pixel x
, which correspond to putting x
in plane (P) S
和像素x
之间的边缘,对应于将x
放入平面(P) x
and T
, which correspond to putting x
in plane (C) 像素x
和T
之间的边缘,对应于将x
放入平面(C) x
and y
, which correspond to edges between planes. 两个像素x
和y
之间的边缘,它们对应于平面之间的边缘。 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. 通过最小割最大流量定理,可以使用最大流量算法(例如Edmonds-Karp)找到最小割。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.