Find volume of 3d peaks in matlab

一笑奈何 提交于 2019-12-06 13:22:21

Here is a suggestion for dealing with this problem:

  1. Define a threshold for z height, or define in any other way which points from the scatter are relevant (the black plane in the leftmost figure below).
  2. Within the resulted points, find clusters on the X-Y plane, to define the different regions to calculate. You will have to define manually how many clusters you want.
  3. for each cluster, perform a Delaunay triangulation to estimate its volume.

Here is an example code for all that:

[x,y,z] = peaks(30); % some data
subplot 131
scatter3(x(:),y(:),z(:),[],z(:),'filled')
title('The original data')
th = 2.5; % set a threshold for z values
hold on
surf([-3 -3 3 3],[-4 4 -4 4],ones(4)*th,'FaceColor','k',...
    'FaceAlpha',0.5)
hold off
ind = z>th; % get an index of all values of interest
X = x(ind);
Y = y(ind);
Z = z(ind);
clustNum = 3; % the number of clusters should be define manually
T = clusterdata([X Y],clustNum); 
subplot 132
gscatter(X,Y,T)
title('A look from above')
subplot 133
hold on
c = ['rgb'];
for k = 1:max(T)
    valid = T==k;
    % claculate a triangulation of the data:
    DT = delaunayTriangulation([X(valid) Y(valid) Z(valid)]);
    [K,v] = convexHull(DT); % get the convex hull indices
    % plot the volume:
    ts = trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),...
        'FaceColor',c(k));
    text(mean(X(valid)),mean(Y(valid)),max(Z(valid))*1.3,...
        num2str(v),'FontSize',12)
end
hold off
view([-45 40])
title('The volumes')

Note: this code uses different functions from several toolboxes. In any case that something does not work, first make sure that you have the relevant toolbox, there are alternatives to most of them.

Having already a mesh, maybe you could use the process described in https://se.mathworks.com/matlabcentral/answers/277512-how-to-find-peaks-in-3d-mesh . If not, making a linear regression on (x,z) or (y,z) plane could make a base for you to find the peaks.

Out of experience in data with plenty of noise, selecting the peaks manually is often faster if you have small set of data to make the analysis. Just plot every peak with its number from findpeaks() and select the ones that are relevant to you. An interpolation to a smoother data can help to solve the problem in the long term (but creates a problem by itself).

Other option will be searching for peaks in the (x,z) and (y,z) planes, then having the amplitude of each peak in an (x) [or (y)] interval and from there make a integration for every area.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!