I need to find the regional maxima of an image to obtain foreground markers for watershed segmentation. I see in matlab use the function imregionalmax()
. As I don't have the matlab software, I use the function scipy.ndimage.filters.maximum_filter()
instead. However, the results from imregionalmax()
and scipy.ndimage.filters.maximum_filter()
are different.
Please help me how to find out the regional maxima of an image. Thanks very much for your help.
The function imregionalmax takes a grayscale image and returns all of the regional maxima pixels in the form of a binary mask.
Regional maxima are connected components of pixels with a constant intensity value, surrounded by pixels with a lower value. BW = imregionalmax( I , conn ) specifies the pixel connectivity, conn .
It appears as if scipy's maximum_filter
returns the actual local max values, while Matlab's imregionalmax
returns a mask with the locations of the local maxima.
I would expect
lm = scipy.ndimage.filters.maximum_filter( img, ... )
msk = (img == lm) #// convert local max values to binary mask
should give you similar results to Matlab's.
I am new to Python but I spent a lot of time to find the 100% equivalent of Matlab's imregionalmax()
. For me, the above, msk = (img == lm)
did NOT work because of my huge 3D arrays. I instead used scikit-images.peak_local_max
as follows:
1) define conn_26
to be 3x3x3 array of one's.
2) coordinates = peak_local_max(3D_img, footprint=conn_26,indices=False,exclude_border=0)
is similar to coordinates = imregionalmax(3D_img,26)
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With