複数粒子の頂点を得たい
Show older comments


下記のコードを実行してregionprops関数のBoundingBoxを用いて粒子の頂点を求めようしたのですが粒子が斜めになっているとBoundingBoxでは頂点を正しく認識することができません.斜めの粒子にも適用できる方法はありますか.
方法がありましたらご教示お願いします.
% 画像を読み込みます。
im = imread('02Al_S0002_2304_1158000001.bmp');
% 画像をグレースケールに変換します。
im_gray = rgb2gray(im);
% 画像を二値化します。
im_bw = imbinarize(im_gray);
% 画像内のオブジェクト(粒子)を見つけます。
stats = regionprops('table', im_bw, 'Centroid', 'Area', 'BoundingBox');
% オブジェクトの形状を解析して、四角形であるかどうかを確認します。
imshow(im);
hold on;
for k = 1:height(stats)
boundingBox = stats.BoundingBox(k,:);
%aspectRatio = boundingBox(3)/boundingBox(4);
%if aspectRatio >= 0.95 && aspectRatio <= 1.05
% 四角形である場合、頂点を見つけます。
x = boundingBox(1);
y = boundingBox(2);
w = boundingBox(3);
h = boundingBox(4);
vertex_x = [x, x+w, x+w, x];
vertex_y = [y, y, y+h, y+h];
plot(vertex_x, vertex_y, 'r*');
%end
end
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
