How can I improve regionprops() use?

1 回表示 (過去 30 日間)
Jacob Ebilane
Jacob Ebilane 2022 年 4 月 4 日
編集済み: Tala 2022 年 4 月 4 日
I have a code I use to get the center of each letter/number in an image using bounding boxes. But for some reason region props detects a segment of the border(Left side of image) as an object. I wanted to know how I can prevent this from happening because it does for my other data. I used this function. I marked the centers of each object r+
function [store,cent] = Segment(appim)
global bd BB coor store
binim = imbinarize(appim);
box = regionprops(binim,'BoundingBox');
bd = [box];
coor = [];
cent=[];
%%
store = [];
for k = 1 : length(box)
BB = box(k).BoundingBox;
coor{k} = BB;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',1);
st = imcrop(appim,[BB(1),BB(2),BB(3),BB(4)]);
sz = size(st);
if (sz(1) < 3)%Disregard small unnecessary artifacts
return
elseif (sz(2) < 3)
return
else
store{k} = st;
cent{k}(1) = (coor{k}(1)+(coor{k}(3)/2));%X Coordinates
cent{k}(2) = (coor{k}(2)+(coor{k}(4)/2)); %Y Coordinates
end
end
cent = {cent{2:length(cent)}}; %Object center coordinates
end
  2 件のコメント
Matt J
Matt J 2022 年 4 月 4 日
But for some reason region props detects a segment of the border(Left side of image) as an object.
What do you mean, "for some reason"? Your image shows that there is a thick white line on the left side of your image.
Jacob Ebilane
Jacob Ebilane 2022 年 4 月 4 日
It doesn't do it on my other samples. It really just does it for this particular one so I assumed that it doesn't put a bounding box on objects that extend up to the edge of an image. Is there a way I could make it so it doesnt include them?

サインインしてコメントする。

採用された回答

Tala
Tala 2022 年 4 月 4 日
編集済み: Tala 2022 年 4 月 4 日
To Matt's point, you do have an object and you should expect to see it's centroid. to avoid this, you can use imcrop to crop out your region of interest, or clean the borders, or pad zeros. If all of your objects at the border are "long", you can filter them out with 'MajorAxisLength'property with regionprops.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by