1

I need to find several (~5) peaks in a 3D surf plot; tried imregionalmax but it's giving me too many maximums and I can't find a way to control it.

I guess the actual peaks I need to find is in my z array which is (x by y), but findpeaks only works for a vector array. Is there an alternative? I've read something about the function squeeze- but not entirely sure how to put it into use it.

The link is an example of the graph and the data points are the examples of the peaks I would need to know.

enter image description here

If anyone could shed some light on this, it'd be great, thanks!

A MCVE I used for imregionalmax is

Z = peaks;
y = linspace(1,100,49);
x = linspace(10,20,49);

[X, Y] = meshgrid(x,y);

figure
surf(X, Y, Z,'EdgeColor','none','FaceColor','interp');
maxZ = imregionalmax(Z);
plot3(X(maxZ),Y(maxZ),Z(maxZ),'r*','MarkerSize',12)
Cindy
  • 11
  • 1
  • 3
  • Could you share what you have tried so far with `imregionalmax` and how the results are different from the desired results? I tested it with `peaks` and `imregionalmax` found the local maxima without problems. – Alex bGoode Apr 30 '18 at 09:16
  • Hi Alex, I've not used peaks, only imregionalmax. This is what I've got, https://1drv.ms/u/s!Al6StzzA7jNMmkXZZv91tk-NWU1H. – Cindy Apr 30 '18 at 13:29
  • Sorry for the confusion. I used `peaks` as test data, because I do not have your data. Can you post your attempt and use peaks instead of the real data. This is called an Minimal, Complete, Verifiable Example (MCVE) and is a prerequisite for a good question. – Alex bGoode Apr 30 '18 at 15:53
  • I'm not sure how to do the formatting on stackoverflow, but here's an MCVE added to the question. It works, no problem, so does the one with my data.. but the problem I had was that it was finding too many peaks as you can see on the matlab figure on the previous link! – Cindy May 01 '18 at 17:34
  • Possible duplicate of [Find peak (regions) in 2D data](https://stackoverflow.com/questions/43852754/find-peak-regions-in-2d-data) – Cris Luengo May 01 '18 at 17:45
  • Your title says "3D", but `Z` is a 2D array, and you need to find its local maxima. The suggested duplicate solves your problem. – Cris Luengo May 01 '18 at 17:46
  • However, this File Exchange submission might be a better fit: https://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder – Cris Luengo May 01 '18 at 17:47

1 Answers1

0

I am not familiarized with deterministic methods to achieve this, but if you do not find any fast solution, you could use metaheuristics to determine the local maxima of the surface.

There are a wide range of algorithms, including:

  • Genetic algorithms
  • Particle Swarm Optimization (PSO)
  • Bees Algorithm
  • ...

I think that there is a recent implementation of PSO in MATLAB, check it out: https://es.mathworks.com/help/gads/particleswarm.html

Víctor Martínez
  • 854
  • 2
  • 11
  • 29