regionprop​sのBounding​Boxの値をつかって​、フィルターをかけた​い

8 views (last 30 days)
Hiroshi Takase
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)

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 23 Feb 2023
Edited: Atsushi Ueno on 23 Feb 2023
>どのようにしたらBoundingBoxの範囲を指定できるか教えていただきたいです
  1. regionprops関数の出力(構造体配列)からBoundingBoxの座標を取り出し行列に変換
  2. BoundingBox行列の「4列目:各BoundingBoxの高さ ÷ 3列目:各BoundingBoxの幅」で縦横比を計算
  3. アスペクト比が所定の規格内に入っているBoundingBoxのインデックスを得る
  4. 得られたインデックスでregionprops関数の出力(構造体配列)にアクセスして各要素を描画する
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の数を数える
ans = 32
  2 Comments
Hiroshi Takase
Hiroshi Takase on 24 Feb 2023
ありがとうございます。やりたいことができました。細胞の画像からの検出をしたいと思いまして作成していたのですが、細長い細胞は数を数えず、できるだけ均等に広がった細胞のみをカウントしたかったのです。ご指摘の通り、細長すぎるものを除外したかったので、縦横比が2:1~1:2(2.0以下、0.5以上) で行うようにします。

Sign in to comment.

More Answers (0)

Categories

Find more on イメージ in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!