在matlab

时间:2017-07-14 15:36:05

标签: matlab plot 3d volume scatter

现在我有一个带有峰值的三维散点图,我需要找到它的体积。我的数据来自图像,因此x和y值表示xy平面上的像素位置,z值是每个像素的像素值。

这是我的散点图:

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

enter image description here

我正在努力寻找"音量"数据的峰值,如下图所示:

enter image description here

我尝试过findpeaks()但它给了我许多局部最大值,没有我正在寻找的两个突出的峰值。另外,我真的坚持如何建立"基地"我的峰值,因为我的数据来自散点图。我也尝试过凸包和线性曲面拟合,并得到: enter image description here enter image description here

但我仍然坚持如何使用这些命令来建立一个自动化的峰值基地"和数量。如果您有任何想法或代码段可以帮助我,请告诉我,因为我很难过,而且我无法在Stack Overflow上找到任何内容。如果真的不清楚,请提前抱歉!非常感谢你!

2 个答案:

答案 0 :(得分:1)

以下是处理此问题的建议:

  1. 定义z高度的阈值,或以任何其他方式定义与散点相关的点(下方最左边图中的黑色平面)。
  2. 在结果点内,在X-Y平面上找到簇,以定义要计算的不同区域。您必须手动定义所需的群集数量。
  3. 对于每个群集,执行Delaunay三角剖分以估计其体积。
  4. peaks demo

    以下是所有这些的示例代码:

    [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')
    

    注意:此代码使用多个工具箱中的不同功能。在任何情况下,某些东西不起作用,首先要确保你有相关的工具箱,大多数都有其他选择。

答案 1 :(得分:0)

已经有一个网格,也许你可以使用https://se.mathworks.com/matlabcentral/answers/277512-how-to-find-peaks-in-3d-mesh中描述的过程。 如果没有,在(x,z)或(y,z)平面上进行线性回归可以为你找到峰值奠定基础。

对于噪声充足的数据经验,如果您只需要很少的数据来进行分析,那么手动选择峰值通常会更快。只需使用findpeaks()中的数字绘制每个峰值,然后选择与您相关的峰值。对更平滑数据的插值有助于长期解决问题(但本身会产生问题)。

其他选项将在(x,z)和(y,z)平面中搜索峰值,然后在(x)[或(y)]区间内具有每个峰值的幅度,并从那里进行积分对于每个地区。