not all peaks are detected using scipy.signal.find_peaks method with prominence parameter

673 Views Asked by At

I'm trying to detect peaks with a certain prominence using the scipy.signal.find_peaks method with its prominence parameter. But the method seems to only detect certain peaks that fulfill the condition but not all of them. The signal and detected peaks(red crosses) are shown in the image. I have encircled a peak that fulfills the condition according to my understanding but isn't detected by the find_peaks method. Can someone explain to me if I just misunderstand the concept of prominence or what the problem could be?

Signal

This is the code that I used for detecting the peaks:

# load image file and apply blur filter

image = cv2.imread(file)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.bilateralFilter(gray,9,75,75)

# detect edges in grayscale value for one horizontal line

peaks,_ = signal.find_peaks(-blur[200,:], prominence=20)
plt.plot(-blur[200,:])
plt.plot(peaks,-blur[200,:][peaks],'rx')
plt.show()

I would expect that the encircled peak would also fulfill the prominence parameter, because the reference would be the lowest value between the peak and the left border of the signal.

1

There are 1 best solutions below

0
On

Prominence is determined by finding the bases on both sides of the peak, not only the left side. On the right side of the peak in question, you quickly hit a higher point than the peak. So the peak's base is the low point between your peak and the higher point to the right of the peak. As a result, the peak has a very small prominence.

From https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_prominences.html

Strategy to compute a peak’s prominence:

  1. Extend a horizontal line from the current peak to the left and right until the line either reaches the window border (see wlen) or intersects the signal again at the slope of a higher peak. An intersection with a peak of the same height is ignored.
  2. On each side find the minimal signal value within the interval defined above. These points are the peak’s bases.
  3. The higher one of the two bases marks the peak’s lowest contour line. The prominence can then be calculated as the vertical difference between the peaks height itself and its lowest contour line.