4次元分布における複数重心点座標の取得について

4 views (last 30 days)
ryo tanaka
ryo tanaka on 17 Oct 2019
Commented: Kenta on 21 Oct 2019
添付図のように4次元分布を作成しました。
4次元分布上に5個の丸い分布があります。
この5個の分布それぞれの重心点を取得したいです。
分布上から1点の重心座標は下記のコードで取得できると思いますが、1つの分布上から任意の個数だけ重心点を取得する方法がありましたら
教えて頂きたいです。
v = squeeze(v);
BW = true(size(v));
W = regionprops3(BW,v,'WeightedCentroid');
WC = W{1,{'WeightedCentroid'}};
1.jpg
  9 Comments
ryo tanaka
ryo tanaka on 18 Oct 2019
attachmentsをクリックしファイルを選択してもやはりエラーが出てきてしまいます。。
スタッフの方にご連絡したいと思います。
a.png
ryo tanaka
ryo tanaka on 19 Oct 2019
すみません、遅くなりました。
ようやくファイルを添付できましたので、お送りいたします。

Sign in to comment.

Accepted Answer

Kenta
Kenta on 19 Oct 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
result.PNG
  6 Comments
ryo tanaka
ryo tanaka on 21 Oct 2019
ご返信ありがとうございます。
>はい、そうですね。またいろいろと試したうえで不明点があれば新たに質問いただければ
>と思います。
ありがとうございます。とても助かります。
質問に回答していただきありがとうございます。
2つとも特に気にすることはないようで安心しました。
また、何か不明な点がありましたら、ご連絡させて頂きます。
Kenta
Kenta on 21 Oct 2019
はい、承知いたしました。解決してよかったです。

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!