MATLAB: How to find peaks in 3d mesh

3dmeshpeaks

Hi, I have a mesh made from data ([Y,X] matrix and Z values) and I would like to find the peaks and report their position. How can I do it?

Best Answer

If your X & Y are monotone, and you have the Image Processing Toolbox, then the imregionalmax function is pretty robust. It handles all of the special cases like flat regions.
[x,y] = meshgrid(linspace(-3,3,10));
z = 10*ones(10,10);
z(2:4,2:4) = 22;
z(6:8,6:8) = 33;
z(2,7) = 44;
z(3,8) = 45;
z(4,9) = 44
surf(x,y,z,'FaceColor','interp')
ix = find(imregionalmax(z));
hold on
plot3(x(ix),y(ix),z(ix),'r*','MarkerSize',24)
Related Question