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:
The vector is here:
vec
There are different ways to find local peaks, here i use the deviation from the local average, then separating the regions, and scanning each region for minimum.
This can easily be solved using
findpeaks
from the Signal Processing Toolbox. Specifically, for your data I had to call it this way: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, theminpeakdistance
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 andlocs
gives you the locations of the peaks in your signal. We need to uselocs
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:As a demonstration, let's plot this signal as well as the peaks that were located by
findpeaks
:The original data is plotted in blue while the detected peaks are plotted in red. This is what I get:
Good luck!