Suppose we have an array like this :
A = peaks
A(A<0)=0 % Remove negative values to make things a bit more simple.
I would like to write a script that is able to select the whole volume of the peaks contained in A.
For example, include all the values that surround a local maximum, until it hits values which are either 0 or a local minimum.
Below is a link to an answered question on a similar but more complicated topic.
Find peak (regions) in 2D data
I tried to use the method found on the answer to the question above, but I had little success for my example. I understand that in this answer, on the line:
im3=imextendedmax(im2,10);
, the value 10 acts as some kind of threshold. If I leave the threshold value at 10, it only selects the upper part of the highest of the three peaks (kind of like selecting the snowy top of a mountain, but I would like the whole mountain). I tried to lower it in order to select the entirety of the peaks, but this is the result I get:
In these results, 6 peaks are identified, but what I want is 3 separated peaks, as described in the picture below:
Hope this is clear enough.