Find volume of 3d peaks in matlab

我的未来我决定 提交于 2019-12-10 10:29:46

问题


right now I have a 3d scatter plot with peaks that I need to find the volumes for. My data is from an image, so the x- and y- values indicate the pixel positions on the xy-plane, and the z value is the pixel value for each pixel.

Here's my scatter plot:

scatter3(x,y,z,20,z,'filled')

I am trying to find the "volume" of the peaks of the data, like drawn below:

I've tried findpeaks() but it gives me many local maxima without the the two prominent peaks that I'm looking for. In addition, I'm really stuck on how to establish the "base" of my peaks, because my data is from a scatter plot. I've also tried the convex hull and a linear surface fit, and get this:

But I'm still stuck on how to use any of these commands to establish an automated peak "base" and volume. Please let me know if you have any ideas or code segments to help me out, because I am stumped and I can't find anything on Stack Overflow. Sorry in advance if this is really unclear! Thank you so much!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/45106812/find-volume-of-3d-peaks-in-matlab

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