0

I have an Image in matlab and to which I did the following command

sample.png

enter image description here

I=imread('sample.png');
   sumCol=sum(I,2);
   plot(sumCol);

Sum Plot

Now based on y value threshold for example 40 I need to get local maxima and two minima for each of those maxima. In the above plot I have mentioned the required red rectangles(maximas) and brown rectangles(minimas). Blue is the original plot and yellow is my manual smoothed curve.

How would I smooth that plot(as otherwise there would be too many maximas) and find those maximas and minimas in matlab?

Naseer
  • 4,041
  • 9
  • 36
  • 72
  • 1
    Look up the concept of "prominence" in mountaineering. It sounds irrelevant but is actually kind of useful. You would take the top three most prominent points. (however, for what you're doing you might be able to just take the top three local peaks, see the `findpeaks` command). I have a script that will calculate prominence but don't have access to it rigjt now but could probably dig it up if you want it. – chessofnerd Aug 28 '16 at 04:14
  • 1
    Also, splines might help you automate the smoothing process. – chessofnerd Aug 28 '16 at 04:16
  • please dig that up. – Naseer Aug 28 '16 at 10:11

1 Answers1

2

I recommend to run a low pass filter on your signal (convlution with a Gaussian or a box car) then it will be much easier to find the max and min.

To find the local maximum use findPeaks (as Suggested by chessofnerd) To find the local mimima use find peaks on the -1*signal.

I recommend you look at the function findpeaks and find exactly what is good for your case http://www.mathworks.com/help/signal/ref/findpeaks.html

% Create a random 1D signal
sig = randn(100,1);

% Create a gaussain window for low pass filtering
gaussFilter = gausswin(5);
gaussFilter = gaussFilter / sum(gaussFilter); % Normalize.

% Low pass filter the data
sigFilters = conv(gaussFilter,sig);

% Find max points (you should config this function for you own needs)
[maxPeaks,maxLocs] = findpeaks(sigFilters);

% Find min points 
[minPeaks,minLocs] = findpeaks(-1*sigFilters);

% Plot
plot(1:length(sigFilters),sigFilters,'b',maxLocs,maxPeaks,'b*',minLocs,-1*minPeaks,'r*')
Amitay Nachmani
  • 3,259
  • 1
  • 18
  • 21
  • can u elaborate it a bit using matlab? – Naseer Aug 28 '16 at 16:06
  • It does not show up the starting min of the first peak and ending min of the last peak.Any idea about that too?............good effort by the way. – Naseer Aug 28 '16 at 20:35
  • Like i said in the answer you need to look at the arguments of findpeaks function there are a lot of ways to config it maybe you need to use one of the options there. – Amitay Nachmani Aug 28 '16 at 20:50