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

5 ビュー (過去 30 日間)
tsuyoshi tsunoda
tsuyoshi tsunoda 2021 年 7 月 18 日
コメント済み: tsuyoshi tsunoda 2021 年 7 月 27 日
顔の左目、右目、口の重心を求めてその重心点を結んだ三角形の面積を求めるプログラムを作りたいです。
画像のようにPhotoshopで切り抜いた画像があるのですが、どのようなプログラムで進めたらいいか分かりません。
まだ勉強を始めたばかりなので教えていただけると幸いです。

採用された回答

Atsushi Ueno
Atsushi Ueno 2021 年 7 月 20 日
編集済み: Atsushi Ueno 2021 年 7 月 27 日
を参考にしました。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 件のコメント
Atsushi Ueno
Atsushi Ueno 2021 年 7 月 27 日
コミュニティプロファイル経由で「出来た三角形の重心を表示する」方法のリクエストがありましたので、回答を編集しました。polyshape オブジェクトとその関数を使っています。
tsuyoshi tsunoda
tsuyoshi tsunoda 2021 年 7 月 27 日
ありがとうございます。

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!