algorithm - Graph cut with python: How to set up the graph correctly? -
I want to use graph cut algorithm on images in my project, I use Python 2.7 This is my code to get it, but it does not work Thank you! If you know the solutions with any other library, then tell me that any suggestions would be really appreciated. Graph for working with, I recommend the
I found, but the documentation does not seem so obvious. I'm making an example, this is my 5 * 5 matrix:
gt; & Gt; An array ([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 1] 9 virtual terminal node, S (source) and T , [20, 21, 22, 23, 24]] (sync) matrix The infinite weight for all pixels of the lowest columns on the left and right should be linked to the arcs. Here's what I want to get:
left_most = concatenate ((1, ashp [0]), N.P. Ranges (ashp [0]). Reshape (1, ashp [0])). Unstable (npuit 64 ) left_most = np.ravel_multi_index (Bayan_ most, Asp) right_most = concatenate ((np. that ((1, Asp [0])) size (A, 1) - 1, NP Krenj (Asp [0]). The new size to (1, Ashaip [0])). volatile (Np.uint64) right_most = np.ravel_multi_index (right_most, A.shape) g.add_grid_tedges (Bayan_ most, Anpikons (Bayan_ most. Shaip) * 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 () makes Python console me in an infinite loop. Not sure about Ryanwyn: What is the graph can be used to cut algorithms is how to create the right graph?
network x package It has many features, including maximum-flowing tasks (for example):
Comments
Post a Comment