繁体   English   中英

从Matlab中的体积数据生成scatter3()的参数

[英]Generate arguments for scatter3() from volumetric data in Matlab

我曾经使用isosurface()渲染体积数据,但是现在我想将它们渲染为点以加快速度。

我拥有的数据是一个3D数组,代表一个3D对象。 如果体素属于该对象,则其值为1,否则为零。

为了使用scatter3(),我需要为那些具有值1的体素生成坐标。我目前使用以下代码来完成这项工作:

function [ x, y, z ] = scatter3_assist( volume )
[R, C, D] = size(volume);
x = zeros( size(volume(:)) );
y = x;
z = x;
idx = 1;
for d=1:D
  for r=1:R
    for c=1:C
      if volume(r, c, d) == 0
        x(idx) = 0; y(idx) = 0; z(idx) = 0;
      else
        x(idx) = C - c + 1; y(idx) = R - r + 1; z(idx) = d;
      end
      idx = idx + 1;
    end
  end
end
x(x==0) = [];
y(y==0) = [];
z(z==0) = [];
x = x - 1;
y = y - 1;
z = z - 1;
end

返回值x,y,z是属于我的对象的体素的坐标,然后我将其称为scatter3(x, y, z, '*'); 渲染它。

有没有更有效的方法来为scatter3()使用的特定体素生成坐标?

我建议使用find查找数组中非零条目的线性索引,然后使用ind2sub转换为索引并执行获取xyz所需的任何转换。 就像是:

I = find(volume ~= 0);
[y, x, z] = ind2sub(size(volume),I); %// note that x and y are switched as in your code above
x = size(volume,2)-x;
y = size(volume,1)-y;

您需要仔细检查xy上的那些操作,以确保它们与您的代码等效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM