gpt4 book ai didi

matlab - 对三角化表面进行子采样时保留颜色 : get indices from reducepatch?

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:54 25 4
gpt4 key购买 nike

我有一个非常密集的镶嵌表面,看起来像这样: White matter dense

这个表面对我来说太密集了,所以我对它进行二次采样以获得更粗糙的表面。为此,我使用了 Matlab 的 reducepatch。功能。这很好用: White matter subsampled

不幸的是,着色基于一个名为 sulcal_depth 的变量,该变量是为我的分割曲面的每个顶点定义的。所以我只需要保留子采样后保留的顶点的脑沟深度信息。本质上,我需要 reducepatch 不仅给我曲面的二次采样版本,还给我它保留的顶点索引。如果我知道保留的索引,我可以只索引我的 sulcal_depth 变量来获取新的深度图。

目前,我按如下方式执行此操作(这也是我为上面的子采样版本着色的方式):

function indices = compute_reduced_indices(before, after)
%% Function to compute the indices of vertices preserved during an operation of
% reducepatch. This allows you to use reducepatch to subsample a surface and
% re-compute an original signal on the vertices for the new subsampled mesh

indices = zeros(length(after), 1);
for i = 1:length(after)
dotprods = (before * after(i, :)') ./ sqrt(sum(before.^2, 2));
[~, indices(i)] = max(dotprods);
end

但是正如您所想象的那样,这是非常慢的,因为 for 循环遍历顶点。我没有足够的内存来向量化循环并一次计算完整的点积矩阵。

有没有聪明的方法让 reducepatch 给我索引,或者有更快的替代方法(有或没有 reducepatch)?

最佳答案

如果reducepath只删除一些顶点但不改变保留点的坐标你可以使用函数ismember:

%Load the "flow" matlab's dataset.
[x,y,z,v] = flow(100);
%Patch the isosurface
p = patch(isosurface(x,y,z,v,-3));
%Reducepatch
rp = reducepatch(p,0.15);
%Create an index of the preserved vertex.
[ind,loc] = ismember(p.Vertices,rp.vertices,'rows');
%Checksum
sum(find(ind) == sort(indices)) == length(indices) %should be = 1

%if you want to preserve the index order:
locb = loc(ind);
subind = find(ind);
[~,revsor] = sort(locb);
ind = subind(revsor);

基准测试

[x,y,z,v] = flow(100);

p = patch(isosurface(x,y,z,v,-3));
rp = reducepatch(p,0.15);
tic
ind = ismember(p.Vertices,rp.vertices,'rows');
toc

before = p.Vertices;
after = rp.vertices;

tic
indices = zeros(length(after), 1);
for i = 1:length(after)
dotprods = (before * after(i, :)') ./ sqrt(sum(before.^2, 2));
[~, indices(i)] = max(dotprods);
end
toc

结果

Elapsed time is 0.196078 seconds. %ismember solution 
Elapsed time is 11.280293 seconds. %dotproduct solution

关于matlab - 对三角化表面进行子采样时保留颜色 : get indices from reducepatch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42614201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com