Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

image processing - Finding peaks MATLAB

I have a vector which includes a gray levels of pixels in a one line of an image. vec=IM(:,65); I showed the parts of the array I want to detect. These parts will be my objects' piksels.

How can I detect these object pixels?

Plot of vec: enter image description here The vector is here: vec

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This can easily be solved using findpeaks from the Signal Processing Toolbox. Specifically, for your data I had to call it this way:

[pks, locs] = findpeaks(max(vec)-vec, 'minpeakdistance', 160, 'minpeakheight', 22);

findpeaks only finds positive peaks (local maxima). As such, what we need to do is invert this so that all of the local minima become local maxima. I did this by taking the maximum value of the vector and subtracting with the vector. Because there are so many local peaks, the minpeakdistance field allows you to find peaks that are at least separated by this much in between each peak. I tuned this to 160. Also, the minimum peak height finds peaks that are greater than a certain number, which I tuned to be 22. pks finds the actual peak values and locs gives you the locations of the peaks in your signal. We need to use locs to find the actual peak data because we performed this on the mirror reflected version of your signal. As such, to get the actual peak data, do this:

pks_final = vecs(loc);

As a demonstration, let's plot this signal as well as the peaks that were located by findpeaks:

plot(1:numel(vec), vec, locs, vec(locs), 'r.');

The original data is plotted in blue while the detected peaks are plotted in red. This is what I get:

enter image description here


Good luck!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...