Finding 2d impulse peaks in MATLAB

smichak picture smichak · Nov 22, 2010 · Viewed 7.3k times · Source

What is the best method for finding impulse peaks (dirac delta) in a 2d matrix.

More specifically, I would like to find the harmonic frequencies of a given image and so I need to find impulse peaks in the image absolute value DFT.

I thought of using findpeaks but there's no 2d version. I also saw earlier posts regarding finding ordinary peaks using imdilate and/or imextendedmax but those find all the peaks in a 2d matrix whereas I am only interested in impulse peaks. I am sure DSP people have a common recipe for this...

Please Help,

Thanks

Answer

Jonas picture Jonas · Nov 22, 2010

What you want to do is find peaks with high contrast. Thus, you need a way to identify local maxima, plus a way to measure the difference between the peak and the surrounding values. Thresholding on this difference will identify the impulse peaks for you.

Assuming your input signal is called signal

%# dilate to find, for every pixel, the maximum of its neighbors
dilationMask = ones(3);
dilationMask(5) = 0;
dilSignal = imdilate(signal, dilationMask);

%# find all peaks
%# peaks = signal > dilSignal;

%# find large peaks peaks by thresholding, i.e. you accept a peak only 
%# if it's more than 'threshold' higher than its neighbors
peaks = (signal - dilSignal) > threshold;

peaks is a logical array with 1's wherever there is a good peak. You can use it to read peak heights from signal with signal(peaks), and to find coordinates using find(peaks).