skimage2.graph.MCP_Connect#
- class skimage2.graph.MCP_Connect(costs, offsets=None, fully_connected=True)#
Bases:
MCPConnect source points using the distance-weighted minimum cost function.
A front is grown from each seed point simultaneously, while the origin of the front is tracked as well. When two fronts meet, create_connection() is called. This method must be overloaded to deal with the found edges in a way that is appropriate for the application.
- __init__(*args, **kwargs)#
- create_connection(id1, id2, tb1, tb2, cost1, cost2)#
create_connection id1, id2, pos1, pos2, cost1, cost2)
Overload this method to keep track of the connections that are found during MCP processing. Note that a connection with the same ids can be found multiple times (but with different positions and costs).
At the time that this method is called, both points are âfrozenâ and will not be visited again by the MCP algorithm.
- Parameters:
- id1int
The seed point id where the first neighbor originated from.
- id2int
The seed point id where the second neighbor originated from.
- pos1tuple
The index of of the first neighbor in the connection.
- pos2tuple
The index of of the second neighbor in the connection.
- cost1float
The cumulative cost at
pos1.- cost2float
The cumulative costs at
pos2.
- 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().)