HI all,

I am trying to add another MCP subclass to use with GIS data in the graph submodule in skimage. In particular, I'd like to allow the left and right borders of the cost np.array to be connected, i.e. to be neighbors. I thought it would suffice to change what are considered edges...so I created new functions to assign edges as should be required for this case (I think), but I get the same results as MCP_Geometric (which makes me think the computation is not taking this into account or I am missing some other required change). Could you help me figure this out? 

Here’s an example of what I’d like the subclass to do

import skimage.graph.mcp as mcp
np.random.seed(0)
a = np.ones((5, 5), dtype=np.float32)
a[0:, 1] = -1
a
'''
array([[ 1., -1.,  1.,  1.,  1.],
       [ 1., -1.,  1.,  1.,  1.],
       [ 1., -1.,  1.,  1.,  1.],
       [ 1., -1.,  1.,  1.,  1.],
       [ 1., -1.,  1.,  1.,  1.]], dtype=float32)
'''

# First column is not connected with columns 3+ under Geometric (as expected)
m = mcp.MCP_Geometric(a, fully_connected=True)
costs, traceback = m.find_costs([(1, 4)])
costs
'''
array([[        inf,         inf,  2.41421356,  1.41421356,  1.        ],
       [        inf,         inf,  2.        ,  1.        ,  0.        ],
       [        inf,         inf,  2.41421356,  1.41421356,  1.        ],
       [        inf,         inf,  2.82842712,  2.41421356,  2.        ],
       [        inf,         inf,  3.82842712,  3.41421356,  3.        ]])
'''

# For GIS should be different
m = mcp.MCP_GIS(a, fully_connected=True)
costs, traceback = m.find_costs([(1, 4)])
costs
'''
Curently
array([[        inf,         inf,  2.41421356,  1.41421356,  1.        ],
       [        inf,         inf,  2.        ,  1.        ,  0.        ],
       [        inf,         inf,  2.41421356,  1.41421356,  1.        ],
       [        inf,         inf,  2.82842712,  2.41421356,  2.        ],
       [        inf,         inf,  3.82842712,  3.41421356,  3.        ]])

Expected (correct one)

array([[ 1.41421356,         inf,  2.41421356,  1.41421356,  1.        ],
       [ 1.        ,         inf,  2.        ,  1.        ,  0.        ],
       [ 1.41421356,         inf,  2.41421356,  1.41421356,  1.        ],
       [ 2.41421356,         inf,  2.82842712,  2.41421356,  2.        ],
       [ 3.41421356,         inf,  3.82842712,  3.41421356,  3.        ]])
'''

My code is in https://github.com/ozak/scikit-image/blob/GIS/skimage/graph/_mcp.pyx

I’d appreciate any help or pointers you can give.

Cheers,

Ömer