skimage2.graph.MCP_Connect#

class skimage2.graph.MCP_Connect(costs, offsets=None, fully_connected=True)#

Bases: MCP

Connect 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 costs array). 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 ends were 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 costs array; this array records the minimum cost path from the nearest/cheapest starting index to each index considered. (If ends were specified, not all elements in the array will necessarily be considered: positions not evaluated will have a cumulative cost of inf. If find_all_ends is ‘False’, only one of the specified end-positions will have a finite cumulative cost.)

tracebackndarray

Same shape as the costs array; this array contains the offset to any given index from its predecessor index. The offset indices index into the offsets attribute, 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_cost is 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 costs array.

Returns:
tracebacklist of n-d tuples

A list of indices into the costs array, starting with one of the start positions passed to find_costs(), and ending with the given end index. These indices specify the minimum-cost path from any given start index to the end index. (The total cost of that path can be read out from the cumulative_costs array returned by find_costs().)