1

I have implemented the solution here. It is a very nice piece of code but it only works to obtain the local, single pixe maxima. What I need is to obtain the maxima and its neighbourhood, lets say a 3x3 matrix centered in the local maxima.

I have the following code that woks only to get the local maxima and minima, but not their surroundings:

def detect_peaks(self, image=None, radius=1):
        """
        Takes an image and detect the peaks usingthe local maximum filter.
        Returns a boolean mask of the peaks (i.e. 1 when
        the pixel's value is the neighborhood maximum, 0 otherwise)
        """

        if (image == None):
            image = self.getParticlesMatrix()

        # define an 8-connected neighborhood
        r = 2
        neighborhood = generate_binary_structure(r,r)

        #apply the local maximum filter; all pixel of maximal value
        #in their neighborhood are set to 1
        local_max = maximum_filter(image, footprint=neighborhood) == image
        #local_max is a mask that contains the peaks we are
        #looking for, but also the background.
        #In order to isolate the peaks we must remove the background from the mask.

        local_min = minimum_filter(image, footprint=neighborhood) == image

        #we create the mask of the background
        background = (image == 0)

        #a little technicality: we must erode the background in order to
        #successfully subtract it form local_max, otherwise a line will
        #appear along the background border (artifact of the local maximum filter)
        eroded_background = binary_erosion(background, structure=neighborhood, border_value=1)

        #we obtain the final mask, containing only peaks,
        #by removing the background from the local_max mask
        detected_peaks = (local_max - eroded_background) + (local_min - eroded_background)

        return np.multiply( detected_peaks, image )

Note that the parameter r=2, I've tryed r=3 and it does not work.

The question is: How can I filter to get the picture local maxima and minima plus their surroundings?

Thanks.

Community
  • 1
  • 1
Santi Peñate-Vera
  • 1,053
  • 4
  • 33
  • 68

0 Answers0