在matlab中查找3d峰的体积 [英] Find volume of 3d peaks in matlab

查看:29
本文介绍了在matlab中查找3d峰的体积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是我的散点图:

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

我试图找到数据峰值的体积",如下图所示:

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

我试过 findpeaks() 但它给了我许多局部最大值,而没有我正在寻找的两个突出的峰值.此外,我真的很困惑如何建立我的峰值的基础",因为我的数据来自散点图.我也试过凸包和线性曲面拟合,得到这个:

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:

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

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!

推荐答案

以下是处理这个问题的建议:

Here is a suggestion for dealing with this problem:

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

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

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.

这篇关于在matlab中查找3d峰的体积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆