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

3 次查看(过去 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 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by