x軸上で、ある点が原点よりどちらにあるのかを検出するプログラム
Mostrar comentarios más antiguos
以前、「顔の切り抜いた部分の重心を求めてその点を結んだ三角形の面積を求めたい」という質問をしてやりたい事が出来るようになったのですが、そこからx軸上で口の重心を原点として、三角形の重心が口の重心(原点)と比較してどちらにあるかというプログラムを作りたいです。
もし、三角形の重心が口の重心(原点)よりも右にあったら「左向き」というテキスト、左にあったら「右向き」といったテキストも出せるようになりたいです。
ご教授願います。
%% Photoshop画像読込
Icolor = imread('/Users/tyt/Desktop/MATLAB/マネキン写真/右中心.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)); % 重心点を結んだ三角形を定義
[trcntx,trcnty] = centroid(triangle); % 三角形の重心
%% グラフィック表示
imshow(Icolor);
hold on;
plot(triangle);
plot(trcntx,trcnty,'*','Color','k');
hold off;

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre イメージ算術 en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!