matlabimage-processingmaximaminima

finding local maxima and minima of the image in matlab


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?


Solution

  • 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*')