skimage2.graph.MCP_Geometric#
- class skimage2.graph.MCP_Geometric(costs, offsets=None, fully_connected=True)#
Bases:
MCPFind distance-weighted minimum cost paths through an n-d costs array.
See the documentation for MCP for full details. This class differs from MCP in that the cost of a path is not simply the sum of the costs along that path.
This class instead assumes that the costs array contains at each position the “cost” of a unit distance of travel through that position. For example, a move (in 2-d) from (1, 1) to (1, 2) is assumed to originate in the center of the pixel (1, 1) and terminate in the center of (1, 2). The entire move is of distance 1, half through (1, 1) and half through (1, 2); thus the cost of that move is
(1/2)*costs[1,1] + (1/2)*costs[1,2].On the other hand, a move from (1, 1) to (2, 2) is along the diagonal and is sqrt(2) in length. Half of this move is within the pixel (1, 1) and the other half in (2, 2), so the cost of this move is calculated as
(sqrt(2)/2)*costs[1,1] + (sqrt(2)/2)*costs[2,2].These calculations don’t make a lot of sense with offsets of magnitude greater than 1. Use the
samplingargument in order to deal with anisotropic data.- __init__(costs, offsets=None, fully_connected=True, sampling=None)#
See class documentation.
- find_costs(starts, ends=None, find_all_ends=True, max_coverage=1.0, max_cumulative_cost=<DEPRECATED>, max_cost=<DEPRECATED>, *, max_step_cost=None)#
Find the minimum-cost path from the given starting points.
This method finds the minimum-cost path to the specified ending indices from any one of the specified starting indices. If no end positions are given, then the minimum-cost path to every position in the costs array will be found.
- Parameters:
- startsiterable
A list of n-d starting indices (where n is the dimension of the
costsarray). The minimum cost path to the closest/cheapest starting point will be found.- endsiterable, optional
A list of n-d ending indices.
- find_all_endsbool, optional
If ‘True’ (default), the minimum-cost-path to every specified end-position will be found; otherwise the algorithm will stop when a a path is found to any end-position. (If no
endswere specified, then this parameter has no effect.)- max_step_costfloat, optional
Cost limit for each step between points. Costs higher than this will form a barrier.
- Returns:
- cumulative_costsndarray
Same shape as the
costsarray; this array records the minimum cost path from the nearest/cheapest starting index to each index considered. (Ifendswere specified, not all elements in the array will necessarily be considered: positions not evaluated will have a cumulative cost of inf. Iffind_all_endsis ‘False’, only one of the specified end-positions will have a finite cumulative cost.)- tracebackndarray
Same shape as the
costsarray; this array contains the offset to any given index from its predecessor index. The offset indices index into theoffsetsattribute, which is a array of n-d offsets. In the 2-d case, if offsets[traceback[x, y]] is (-1, -1), that means that the predecessor of [x, y] in the minimum cost path to some start position is [x+1, y+1]. Note that if the offset_index is -1, then the given index was not considered.
- Other Parameters:
- max_costDEPRECATED
Deprecated in favor of
max_step_cost.Deprecated since version 0.26.
- max_cumulative_costDEPRECATED
max_cumulative_costis deprecated.Deprecated since version 0.26.
- goal_reached(index, cumcost)#
int goal_reached(int index, float cumcost) This method is called each iteration after popping an index from the heap, before examining the neighbors.
This method can be overloaded to modify the behavior of the MCP algorithm. An example might be to stop the algorithm when a certain cumulative cost is reached, or when the front is a certain distance away from the seed point.
This method should return 1 if the algorithm should not check the current point’s neighbors and 2 if the algorithm is now done.
- offsets#
- traceback(end)#
Trace a minimum cost path through the pre-calculated traceback array.
This convenience function reconstructs the the minimum cost path to a given end position from one of the starting indices provided to find_costs(), which must have been called previously. This function can be called as many times as desired after find_costs() has been run.
- Parameters:
- enditerable
An n-d index into the
costsarray.
- Returns:
- tracebacklist of n-d tuples
A list of indices into the
costsarray, starting with one of the start positions passed to find_costs(), and ending with the givenendindex. These indices specify the minimum-cost path from any given start index to theendindex. (The total cost of that path can be read out from thecumulative_costsarray returned by find_costs().)