4次元分布における複数重心点座標の取得について
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
添付図のように4次元分布を作成しました。
4次元分布上に5個の丸い分布があります。
この5個の分布それぞれの重心点を取得したいです。
分布上から1点の重心座標は下記のコードで取得できると思いますが、1つの分布上から任意の個数だけ重心点を取得する方法がありましたら
教えて頂きたいです。
v = squeeze(v);
BW = true(size(v));
W = regionprops3(BW,v,'WeightedCentroid');
WC = W{1,{'WeightedCentroid'}};
9 Kommentare
Akzeptierte Antwort
Kenta
am 19 Okt. 2019
こんにちは。データを送っていただきありがとうございます。
X,Y,Z,vとありますが、X-Zは、vのボクセル座標を定めるためのグリッドで、それぞれのグリッド内の値が
そのX(やY・Z)座標に対応している、そして、vが実際にそのプロットの持つ強度である、ということでしょうか。
コメントにて、コードも添付いただきありがとうございました。申し訳ございませんが、こちらで改めてコードを書きました。
質問者様は、上のようにボクセルを定義して、各重心を求める方針だったと読み取りましたが、
下では、ポイントクラウドで処理しています。下のように書けば重心を求めるまでかなり短く書くことができます。
重心は一般的な3D上でのものを計算しています。本来はこの過程でvの強度を利用して、重みつきの重心を定義するのですかね?また、4次元、というキーワードがありますが、これを4D画像としてとらえるなら、vの値を利用せず重心を求めているのでもう少し変更する必要があるとは思います。適宜変更いただければと思います。
詳細は適宜コード内のコメントをご参照ください。よろしくお願いいたします。
clear;clc;close all
% data loading
load V.mat
% find out the points with non-zero intensity
idx=find(v~=0);
% extract the XYZ coordinate
[subx, suby, subz]=ind2sub(size(v),idx);
% acquire the intensity, it was not used, though
int = v(idx);
% convert the xyz into pointcloud variable
ptCloud=pointCloud([subx, suby, subz]);
% figure;pcshow(ptCloud,'MarkerSize',50)
% closest pair of points whose euclidean distance is less than "minDistance"
% was assigned into the same cluster
minDistance = 3;
[labels,numClusters] = pcsegdist(ptCloud,minDistance);
% note that each cluster could be segmented based on the distance
figure;pcshow(ptCloud.Location,labels+1,'MarkerSize',50)
colormap([hsv(numClusters);[0 0 0]])
title('Segmented Cloud Clusters');hold on
% the centroid of each cluster was caclulated and plotted on the 3D space
% note that any weighting based on the intensity was not applied
s = countcats(categorical(labels));
[~, c_label] = sort(s,'descend');
for i=1:5
roi_idx=find(labels==c_label(i));
roi = ptCloud.Location(roi_idx,:);
xyz=mean(roi,1);
plot3(xyz(1),xyz(2),xyz(3),'o','MarkerSize',20,'MarkerFaceColor','w');hold on
end
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu ライティング、透明度、およびシェーディング finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!