How to count hight intensity points from improfile

1 view (last 30 days)
I wanted to count the high peaks as seen in image. this is the result of improfile() function of a binarized image.
gggg.JPG

Answers (3)

Alexandre Turenne
Alexandre Turenne on 22 Nov 2019
Edited: Alexandre Turenne on 22 Nov 2019
look for 1s or 0.99 (idk if your function reaches 1) in the vector c
This wouldn't count the number of peaks but tell you how many times it is equal to 1
For counting the peaks I would do a rolling window. Something like that:
length_window_dist = 20 %nb of distance to look back
nb_peaks = 0
for i=1:length(c)
if c(i) == 1
%part i < initial window
if i<=length_window_dist && nb_peaks == 0
nb_peaks = nb_peaks+1
%part where i>intial window
else
% we dont want to see a 1 in the 20 last periods
if nnz(c(i-length_window_dist:i-1)==1) == 0 %lookback for the rolling window if c =1
nb_peaks = nb_peaks+1
end
end
end
end
there is surely a more efficient way to do this

Walter Roberson
Walter Roberson on 22 Nov 2019
diff(values > some_threshold)
This will be:
  • 1 at every leading edge of a rise (true minus false)
  • -1 at every trailing edge of a rise (false minus true)
  • 0 outside the rises (false minus false)
  • 0 inside the rises (true minus true)
So to count peaks, count the 1's.
"Your threshold should be chosen taking into consideration how you want to treat those double peaks. If you want to count them together as a single event, set the threshold below the minimum that shows up between joined peaks -- assuming that the join is above the baseline. If you want to count the dual peaks as seperate events, set the threshold above about 0.7
Your data just after 500 might present some problems.

Image Analyst
Image Analyst on 22 Nov 2019
Edited: Image Analyst on 22 Nov 2019
Try this:
[~, numPeaks] = bwlabel(yourProfile > 0.7);
  1 Comment
Image Analyst
Image Analyst on 22 Nov 2019
If you want to combine short, close-together peaks, you can use the imdilate() function.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!