Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between imregionalmax() of matlab and scipy.ndimage.filters.maximum_filter

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.

like image 687
user30985 Avatar asked Dec 22 '14 07:12

user30985


People also ask

How does imregionalmax work?

The function imregionalmax takes a grayscale image and returns all of the regional maxima pixels in the form of a binary mask.

What is regional maxima?

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 .


2 Answers

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.

like image 69
Shai Avatar answered Sep 28 '22 15:09

Shai


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 :)

like image 29
Claudia Avatar answered Sep 28 '22 15:09

Claudia