- regionprops関数の出力(構造体配列)からBoundingBoxの座標を取り出し行列に変換
- BoundingBox行列の「4列目:各BoundingBoxの高さ ÷ 3列目:各BoundingBoxの幅」で縦横比を計算
- アスペクト比が所定の規格内に入っているBoundingBoxのインデックスを得る
- 得られたインデックスでregionprops関数の出力(構造体配列)にアクセスして各要素を描画する
regionpropsのBoundingBoxの値をつかって、フィルターをかけたい
4 views (last 30 days)
Show older comments
Hiroshi Takase
on 22 Feb 2023
Commented: Hiroshi Takase
on 24 Feb 2023
データを regionpropsにて計測しているのですが、そのうち認識されたエリアの縦横比をBoundingBoxないのデータをつかって計算し縦横比が1:1~1:2のもの以外は除外して、数を数え、また該当したものを図に書き入れたいのですが、
以下の順で処理しているのですが、どのようにしたらBoundingBoxの範囲を指定できるか教えていただきたいです
status_t= regionprops((I_seg_t > 1),'Centroid','BoundingBox');
numblobs_t =size(status_t,1);
Ir = insertShape(RGBImage,'Rectangle',cat(1,status_t.BoundingBox),'Color','White');
Ir = insertMarker(Ir,cat(1,status_t.Centroid),'*','Color','Blue');
figure,imshow(Ir)
0 Comments
Accepted Answer
Atsushi Ueno
on 23 Feb 2023
Edited: Atsushi Ueno
on 23 Feb 2023
>どのようにしたらBoundingBoxの範囲を指定できるか教えていただきたいです
RGBImage = imread('rice.png'); % サンプル用のグレースケールイメージ
I_seg_t = bwareaopen(imbinarize(RGBImage - imopen(RGBImage, strel('disk',15))), 50); % 2値化など
status_t = regionprops(I_seg_t,'Centroid','BoundingBox');
BB = cat(1,status_t.BoundingBox); % Bounding Box 内のデータ
AR = BB(:,4)./BB(:,3); % 縦横比
index = (AR >= 0.5) & (AR <= 1.0); % BoundingBoxの縦横比が規格内のインデックス
Ir = insertShape(RGBImage,'Rectangle',cat(1,status_t(index).BoundingBox),'Color','White');
Ir = insertMarker(Ir,cat(1,status_t(index).Centroid),'*','Color','Blue');
figure,imshow(Ir)
sum(index) % 縦横比が1:1~1:2の数を数える
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!