Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Matt J
Matt J am 23 Okt. 2018
Bearbeitet: Matt J am 23 Okt. 2018
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by