How to find coordinates of the centroid of objects(found with bwlabel function) with area more than 3 pixels in the attached image?

5 ビュー (過去 30 日間)
Hello all, I have the attached image and using bwlabel MATLAB built-in function, I got the number of objects. Then I want to find the coordinates of the centroid of objects with more than three pixels;In the code I wrote bwlabel gives me 1279 objects and the with this line(allAreas= allAreas(allAreas>3);),the number of objects will be 665 in the workspace, but when I wrote the for loop,it started with the first object in the stats structure which its area is 1 pixel. Thanks
a = imread('PrimaryOrange.jpg');
bg=rgb2gray(a);
threshold = 20;
bw=bg> threshold;
out=bw;
L = bwlabel(out);
[labeledImage, numberOfObject] = bwlabel(out);
props = regionprops(labeledImage, 'Area');
allAreas = [props.Area];
stats = regionprops('table',labeledImage,'Area','Centroid',...
'MajorAxisLength','MinorAxisLength','Perimeter')
allAreas= allAreas(allAreas>3);
for i= 1 : numberOfObjects
x_object= stats.Centroid(i,1);
y_object= stats.Centroid(i,2);
new_x= ceil(x_object )+ 30
new_y=ceil(y_object)+30
new_x_y= [new_x new_y]
if BWdapi(new_x_y) == 1
antibody = [antibody ; new_x_y]
end
end

採用された回答

Matt J
Matt J 2018 年 10 月 23 日
編集済み: Matt J 2018 年 10 月 23 日
You could just filter out all the objects that are too small before doing any of your other processing.
bw=bwareafilt( bg> threshold, [4,inf]);
Or, do
stats=stats(allAreas>3);
  3 件のコメント
Penny13
Penny13 2018 年 10 月 23 日
Thanks so much. This worked.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by