Search code examples
pythonimage-segmentationscikit-image

Changes to peak_local_max in skimage.feature: how do I get the boolean array shaped like the image and not the local feature coordinates?


Like the title says essentially. Since we the 'indices' keyword is no longer available, how do we pass to the peak_local_max function of skimage.feature that we want the actual array of booleans and not the coordinates? I know I can do it myself by passing the coordinates to some custom function, but I think I'm just missing the new way to do it. Here's the old way I would do it in my code:

local_maxi = peak_local_max(distance, indices=False, min_distance=50, labels=dapi_mask_oksize)

but this returns an error that the keyword 'indices' is unexpected...

I already tried simply deleting the 'indices' keyword, but now the function seems to work as if it were given 'indices=True' in the old version.


Solution

  • You can use the following two lines of Python to get the boolean array:

    local_maxi = peak_local_max(distance, min_distance=50, labels=dapi_mask_oksize)
    peaks_mask = np.zeros_like(distance, dtype=bool)
    peaks_mask[local_maxi] = True
    

    I think it would be a useful addition to scikit-image to write a helper function in skimage.util to do this, because many functions return coordinates:

    def coords_to_mask(coords, shape):
        mask = np.zeros(shape, dtype=bool)
        mask[coords] = True
        return mask
    

    In the meantime though you can use your own!