顔の切り抜いた部分の​重心を求めて、その点​を結んだ三角形の面積​を求めたい

18 Ansichten (letzte 30 Tage)
tsuyoshi tsunoda
tsuyoshi tsunoda am 18 Jul. 2021
Kommentiert: tsuyoshi tsunoda am 27 Jul. 2021
顔の左目、右目、口の重心を求めてその重心点を結んだ三角形の面積を求めるプログラムを作りたいです。
画像のようにPhotoshopで切り抜いた画像があるのですが、どのようなプログラムで進めたらいいか分かりません。
まだ勉強を始めたばかりなので教えていただけると幸いです。

Akzeptierte Antwort

Atsushi Ueno
Atsushi Ueno am 20 Jul. 2021
Bearbeitet: Atsushi Ueno am 27 Jul. 2021
を参考にしました。regionprops関数で連結要素の重心を計算できます。比較的小さな連結要素も拾ってしまうので、面積の比較的大きな連結要素に絞ると目的の連結要素(目と口)のみ選択出来ました。
%% Photoshop画像読込
Icolor = imread('Photoshop.png');
I = rgb2gray(Icolor); % グレースケール化
bgc = I(10,10); % 背景色の選択
%% 目と口の重心を求める
BW = I > bgc + 1 | I < bgc - 1; % (ほぼ)背景と背景以外で2値化(imbinarize)
s = regionprops(BW,'centroid'); % イメージ内の連結要素の重心を計算
Areas = regionprops(BW,'Area'); % 各重心位置計算されたエリアの面積
centroids = cat(1,s.Centroid); % 重心を格納する構造体配列を単一の行列に連結
centroids = centroids(cat(1,Areas.Area) > 10, :); % 面積の大きな連結要素のみ選択
%% 目と口の重心点を結んだ三角形の面積と重心を求める
triangle = polyshape(centroids(:,1),centroids(:,2)); % 重心点を結んだ三角形を定義
triangle_area = area(triangle); % 三角形の面積
[trcntx,trcnty] = centroid(triangle); % 三角形の重心
%% グラフィック表示
imshow(Icolor);
hold on;
plot(triangle);
plot(trcntx,trcnty,'*','Color','k');
text(trcntx+100,trcnty,['area:' num2str(triangle_area)]);
text(trcntx-200,trcnty+30,['centroid:[' num2str(trcntx) ',' num2str(trcnty) ']']);
hold off;
  3 Kommentare
Atsushi Ueno
Atsushi Ueno am 27 Jul. 2021
コミュニティプロファイル経由で「出来た三角形の重心を表示する」方法のリクエストがありましたので、回答を編集しました。polyshape オブジェクトとその関数を使っています。
tsuyoshi tsunoda
tsuyoshi tsunoda am 27 Jul. 2021
ありがとうございます。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!