how can find size of this objects in a binary image?
Mostra commenti meno recenti

hi I have a binary image and it has some objects...how can find size of this objects??Is there any toolbox in matlab for this??
Risposta accettata
Più risposte (4)
You can do it in few steps. If your input image is I then:
%Step 1: Label each object using the following code.
I = im2bw(I); % be sure your image is binary
L = bwlabel(I); % label each object
%Step 2: see the label of each object
s = regionprops(L, 'Centroid');
imshow(I)
hold on
for k = 1:numel(s)
c = s(k).Centroid;
text(c(1), c(2), sprintf('%d', k), ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle');
end
hold off
% Step 3: find the area of the object you want using its label
Obj = (L == 1) % 1 is the label number of the first object.
figure, imshow(Obj);
Area = regionprops(Obj,'Area') % the answer
Now, for example if you want to find the area of object number 3, the just change number 1 to 3.
Obj = (L == 3) where 3 is the label number of the third object.
Area is the number of pixels in the object.
Hope that will help.
1 Commento
azima ariff
il 3 Dic 2018
this help for my project..thanks...
Matt J
il 24 Set 2014
How about,
regionprops(...,'Area')
Image Analyst
il 24 Set 2014
Modificato: Image Analyst
il 23 Ott 2021
Of course sara. I thought you've already run across my image segmentation tutorial by now. Run it here http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862, replacing the coin image with yours. It will tell you the areas, centroids, bounding boxes, coordinates of the perimeter, etc.
Basically, it's
mask = grayImage > 128; % Create a logical binary image.
props = regionprops(mask, 'Area'); % Find areas of each blob and put into a structure.
allAreas = [props.Area]
Categorie
Scopri di più su Image Processing and Computer Vision in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!