How to find peaks in 3d mesh?

조회 수: 32 (최근 30일)
OldCar
OldCar 2016년 4월 6일
답변: Poison Idea fan 2024년 5월 1일
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?

채택된 답변

Mike Garrity
Mike Garrity 2016년 4월 6일
편집: Mike Garrity 2016년 4월 6일
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)
  댓글 수: 2
OldCar
OldCar 2016년 4월 6일
편집: OldCar 2016년 4월 11일
I have a big set of values and it say that index exceeds matrix dimensions. What can I do?
Chibuzo Nnonyelu
Chibuzo Nnonyelu 2018년 12월 13일
You need to use the meshed X and Y. As in, fetched your ix indices from the meshed X and Y.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

donghun lee
donghun lee 2018년 7월 3일
Same Error :)

Cristian Alistarh
Cristian Alistarh 2020년 6월 17일
편집: Cristian Alistarh 2020년 6월 17일
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
Memo Remo
Memo Remo 2020년 6월 20일
Cristian Alistarh
Cristian Alistarh 2020년 7월 7일
OK, sounds better than my suggestion.

댓글을 달려면 로그인하십시오.


Poison Idea fan
Poison Idea fan 2024년 5월 1일
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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by