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

查看:79
本文介绍了在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. 在结果点内,在XY平面上找到簇,以定义要计算的不同区域。您将必须手动定义所需的群集数。

  3. 对于每个群集,执行Delaunay三角剖分以估计其容量。

以下是所有示例代码:

[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天全站免登陆