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
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!