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

조회 수: 18 (최근 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!