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

0 Comments
Accepted Answer
  Atsushi Ueno
      
 on 20 Jul 2021
        
      Edited: Atsushi Ueno
      
 on 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 Comments
  Atsushi Ueno
      
 on 27 Jul 2021
				コミュニティプロファイル経由で「出来た三角形の重心を表示する」方法のリクエストがありましたので、回答を編集しました。polyshape オブジェクトとその関数を使っています。
More Answers (0)
See Also
Categories
				Find more on 領域とイメージのプロパティ in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!