Reputation: 11
How do I threshold an image to find the local maxima in a robust way?
I know I can just look at the data, visually guess at some appropriate h value, and do imextendedmax(I, h)
where h is the threshold, but I'm looking for a more robust way to do it in MATLAB. I'm pretty new to MATLAB and coding so this is all foreign...
I'd need to do thresholding because of a noisy background (still somewhat noisy even after I filter it). imregionalmax()
would therefore give way more local maximas than I need.
Upvotes: 1
Views: 2790
Reputation: 23
See whether Otsu's method will do the job for you.Otsu's method
It's implemented as part of the Image processing toolbox."Matlab help for Otsu's Method"
level = graythresh(I)
Upvotes: 1
Reputation: 213120
Generate a histogram, find the max valued bin, then set your threshold at some fixed offset below this.
Or for a slightly more sophisticated approach, sum the histogram bin counts starting at the max value and work downwards until you have accumulated some fixed percentage of the total population, e.g. 0.1%, and set your threshold there.
Upvotes: 1