How to find peaks in 3d mesh?
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (3)
donghun lee
el 3 de Jul. de 2018
0 votos
Same Error :)
Cristian Alistarh
el 17 de Jun. de 2020
Editada: Cristian Alistarh
el 17 de Jun. de 2020
I think you got this error:
Index exceeds the number of array elements
As stated above, you need to use the meshed X and Y.
Digging further into this, the indicies of the output of the imregionalmax function is given in linear array indicies and not 2D (row, columns) as one would normally expect. I had the same problem and another way to solve this is to use the convert linear indices to subscripts function ind2sub
ix = find(imregionalmax(z));
[a,b] = ind2sub(size(z),ix);
plot3(x_init(a),y_init(b),z(a,b),'r*','MarkerSize',24)
I am not sure if it will give you 100% what you are looking for, but explains the previous behaviour and another way on how to fix it.
5 comentarios
Memo Remo
el 17 de Jun. de 2020
Hello Cristian,
I have a 3D point cloud surface that is converted to a (n x 3) matrix (each row is a point location). I want to find all local exterma of this surface. Does your method work for this problem too?
Best,
M
Cristian Alistarh
el 18 de Jun. de 2020
Editada: Cristian Alistarh
el 18 de Jun. de 2020
Hi Memo Remo,
Yes, it does. By looking at the definition of imregionalmax you can see it accepts as input a numeric array of any dimension.
So you will have a set of 3 coordinates for each row, together with the value assgined for this coordiante. In total, 4 variables. You apply the the imregionalmax to the values themselves, which should give you what you want. So the code becomes:
ix = find(imregionalmax(z));
[a,b,c] = ind2sub(size(z),ix);
In my own code, I have defined the 3D positions based on theta, phi coordiantes and it works. I imagine that if you get into some trouble with using the cartesian coordinates, you can change to spherical and it should work.
Hope this helps,
Cristian
Hi Cristian,
Thanks for your help.
Actually I have only the coordinates without any other values. Please consider that my (n x 3) data matrix only contains some points on the suface of a part of the earth including mountains and valleys. I need to find the peak of the mountains and bottom of the valleys. Attached is a sample of thses files. If I use the spherical coordinate then there sould be still three coordinates (r, phi and theta), is this correct?
Thanks,
M
Memo Remo
el 20 de Jun. de 2020
Found the answer. Please refer to the following post.
Cristian Alistarh
el 7 de Jul. de 2020
OK, sounds better than my suggestion.
Poison Idea fan
el 1 de Mayo de 2024
0 votos
Matlab 2024a has a new function islocalmax2 that can find peaks for 3D surface.
https://www.mathworks.com/help/matlab/ref/islocalmax2.html#mw_ecf7d164-82f0-4175-b939-b61c0f9c7f29
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
