プロジェクトの画像でグラフカットアルゴリズムを使用したいのですが、python 2.7を使用しています。pymaxflow の実装
を見つけましたが、ドキュメントはあまり明確ではないようです。私は例を作ります、ここに私の5 * 5行列があります:
>>> A
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
仮想ターミナル ノードS (ソース) とT (シンク) は、それぞれ行列の左端と右端の列のすべてのピクセルに無限の重みアークで接続する必要があります。これが私が取得したいものです:
これを取得するための私のコードは次のとおりですが、機能しません
left_most = concatenate((np.zeros((1, A.shape[0])), np.arange(A.shape[0]).reshape(1, A.shape[0]))).astype(np.uint64)
left_most = np.ravel_multi_index(left_most, A.shape)
right_most = concatenate((np.ones((1, A.shape[0])) * size(A, 1) - 1, np.arange(A.shape[0]).reshape(1, A.shape[0]))).astype(np.uint64)
right_most = np.ravel_multi_index(right_most, A.shape)
g.add_grid_tedges(left_most, np.ones(left_most.shape) * np.inf, np.zeros(left_most.shape))
g.add_grid_tedges(right_most, np.zeros(right_most.shape), np.ones(right_most.shape) * np.inf)
g.maxflow()
Python コンソールを無限ループにします。実装についてよくわかりません: グラフ カット アルゴリズムで使用できる正しいグラフを作成する方法は何ですか?
ありがとう!
Ps別のライブラリでの解決策を知っている場合は、教えてください。どんな提案でも大歓迎です。