二値化した画像の白の重心が知りたい。
54 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
パンダ
le 23 Nov 2021
Réponse apportée : Atsushi Ueno
le 27 Nov 2021
ラインがある画像を読み取り。ラインを白となるように閾値を 決定する. 白色に判定された座標䛾平均座標 を求めることでライン䛾重心点を計 算したいのですがどのようにしたらよいですか? この重心点が常に画像䛾中心に なるようにしたいです。.
Réponse acceptée
Atsushi Ueno
le 27 Nov 2021
>白色に判定された座標䛾平均座標 を求めることでライン䛾重心点を計算したいのですがどのようにしたらよいですか?
上記関数で二値化画像の連続領域を認識でき、かつそのプロパティ(重心等)の計測も出来ます。
I = imread('lighthouse.png'); % これが「ラインがある画像」だとします
BW = rgb2gray(I) > 200; % 画像の二値化
imshow(BW);
s = struct2cell(regionprops(BW, 'basic'))'; % 'basic'=('Area','Centroid','BoundingBox')
s = sortrows(s, 1, 'descend'); % 'Area'で降順にソートし最大面積の連続領域を先頭要素にする
s(1,:) % [面積], [重心のx座標,y座標], [左上のx座標,y座標,幅,高さ]
imshow(I); hold on;
plot(s{1,2}(1,1),s{1,2}(1,2),'b*'); % 重心を青色の'*'で表示
rectangle('Position',s{1,3},'EdgeColor','y'); % BoundingBoxを黄色の四角で表示
hold off;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur イメージ タイプの変換 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!