Possible bug in Random Walker (markers with isolated seeds)

Hi,

I’d like to report a possible bug in the random walker implementation. Likely, the isolated seeds are not handled correctly. See the MWE below. In the _preprocess routine, the label 2 is correctly identified as an isolated seed first, but in a subsequect “if” clause and below, it is ommited. As a result, there is no edge connected to the label 2 and the whole routine fails with an exception “Index (6) out of range” on line “rows = lap_sparse[unlabeled_indices, :]”. The MWE goes like this:

import numpy as np
from skimage.segmentation import random_walker

data = np.asarray([[12823, 12787, 12710], [12883, 13425, 12067], [11934, 11929, 12309]])
markers = np.asarray([[0, -1, 2], [0, 0, -1], [1, 0, 0]])
labels = random_walker(data, markers, beta=10)

Regards,

David

Thank you @dmotl! That indeed looks like a bug. Thanks in particular for the super tiny minimum working example which made it super easy to confirm. I’ve reported it as an issue on our issue tracker here:

Please follow the discussion there.