I am doing a segmentation of ilium from MRI sequence using random walker algorithm. I segmented it from the easiest slice of the sequence and then I want to iterate over the sequence using previous bone segmentation (eroded and dilated) as inner and outer markers. I use the following code to label markers :

markers = np.zeros(bone_mark.shape)
out_mark = np.invert(dilation(bone_mark, disk(10)))
in_mark = erosion(bone_mark, disk(5))
markers[out_mark == True] = 1
markers[in_mark == True] = 2

where bone_mark is the segmentation of ilium of previous slice. It works fine the first time, but when I run this in a loop, the second iteration fails to combine labels in marker array. Here you can see an example of marker image in first and second iterations :

first iteration markers

second iteration markers

I checked out_mark and in_mark in both iterations and they are fine, just like they should be. It looks mysterious to me and I have no idea how to fix this problem. Could you please share your thoughts on this problem?

1 Answers

tanya On Best Solutions

I found the problem, it was due to the output type of skimage.segmentation.random_walker which is not bool but :

array of ints of same shape as data, in which each pixel has been labeled according to the marker that reached the pixel first

so ones and twos in my case.

The first segmentation of the easiest slice was done with another algorithm, and it was a bool array.